<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998

-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-8"></span><span class="hs-pragma">{-# LANGUAGE MultiWayIf #-}</span><span>
</span><span id="line-9"></span><span class="hs-pragma">{-# LANGUAGE TypeFamilies #-}</span><span>
</span><span id="line-10"></span><span>
</span><span id="line-11"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}</span><span>
</span><span id="line-12"></span><span>
</span><span id="line-13"></span><span class="hs-comment">-- | Handles @deriving@ clauses on @data@ declarations.</span><span>
</span><span id="line-14"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Tc.Deriv</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#tcDeriving"><span class="hs-identifier">tcDeriving</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#DerivInfo"><span class="hs-identifier">DerivInfo</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-19"></span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Hs.html"><span class="hs-identifier">GHC.Hs</span></a></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html"><span class="hs-identifier">GHC.Driver.Session</span></a></span><span>
</span><span id="line-22"></span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Monad.html"><span class="hs-identifier">GHC.Tc.Utils.Monad</span></a></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.Family.html"><span class="hs-identifier">GHC.Tc.Instance.Family</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Origin.html"><span class="hs-identifier">GHC.Tc.Types.Origin</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Predicate.html"><span class="hs-identifier">GHC.Core.Predicate</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Infer.html"><span class="hs-identifier">GHC.Tc.Deriv.Infer</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html"><span class="hs-identifier">GHC.Tc.Deriv.Utils</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Validity.html"><span class="hs-identifier">GHC.Tc.Validity</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.Validity.html#allDistinctTyVars"><span class="hs-identifier">allDistinctTyVars</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.TyCl.Class.html"><span class="hs-identifier">GHC.Tc.TyCl.Class</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.TyCl.Class.html#instDeclCtxt3"><span class="hs-identifier">instDeclCtxt3</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.TyCl.Class.html#tcATDefault"><span class="hs-identifier">tcATDefault</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Env.html"><span class="hs-identifier">GHC.Tc.Utils.Env</span></a></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Generate.html"><span class="hs-identifier">GHC.Tc.Deriv.Generate</span></a></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Validity.html"><span class="hs-identifier">GHC.Tc.Validity</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.Validity.html#checkValidInstHead"><span class="hs-identifier">checkValidInstHead</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html"><span class="hs-identifier">GHC.Core.InstEnv</span></a></span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Instantiate.html"><span class="hs-identifier">GHC.Tc.Utils.Instantiate</span></a></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html"><span class="hs-identifier">GHC.Core.FamInstEnv</span></a></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Gen.HsType.html"><span class="hs-identifier">GHC.Tc.Gen.HsType</span></a></span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html"><span class="hs-identifier">GHC.Core.TyCo.Rep</span></a></span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html"><span class="hs-identifier">GHC.Core.TyCo.Ppr</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html#pprTyVars"><span class="hs-identifier">pprTyVars</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-40"></span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Rename.Bind.html"><span class="hs-identifier">GHC.Rename.Bind</span></a></span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Rename.Env.html"><span class="hs-identifier">GHC.Rename.Env</span></a></span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Rename.Module.html"><span class="hs-identifier">GHC.Rename.Module</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Rename.Module.html#addTcgDUs"><span class="hs-identifier">addTcgDUs</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Rename.Utils.html"><span class="hs-identifier">GHC.Rename.Utils</span></a></span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Unify.html"><span class="hs-identifier">GHC.Core.Unify</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Unify.html#tcUnifyTy"><span class="hs-identifier">tcUnifyTy</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Class.html"><span class="hs-identifier">GHC.Core.Class</span></a></span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Type.html"><span class="hs-identifier">GHC.Core.Type</span></a></span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html"><span class="hs-identifier">GHC.Utils.Error</span></a></span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html"><span class="hs-identifier">GHC.Core.DataCon</span></a></span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html"><span class="hs-identifier">GHC.Data.Maybe</span></a></span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.Reader.html"><span class="hs-identifier">GHC.Types.Name.Reader</span></a></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.html"><span class="hs-identifier">GHC.Types.Name</span></a></span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.Set.html"><span class="hs-identifier">GHC.Types.Name.Set</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">NameSet</span></span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html"><span class="hs-identifier">GHC.Core.TyCon</span></a></span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html"><span class="hs-identifier">GHC.Tc.Utils.TcType</span></a></span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.html"><span class="hs-identifier">GHC.Types.Var</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Var</span></span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html"><span class="hs-identifier">GHC.Types.Var.Env</span></a></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html"><span class="hs-identifier">GHC.Types.Var.Set</span></a></span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Builtin.Names.html"><span class="hs-identifier">GHC.Builtin.Names</span></a></span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html"><span class="hs-identifier">GHC.Types.SrcLoc</span></a></span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-63"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Outputable</span></span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.FastString.html"><span class="hs-identifier">GHC.Data.FastString</span></a></span><span>
</span><span id="line-65"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html"><span class="hs-identifier">GHC.Data.Bag</span></a></span><span>
</span><span id="line-66"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.FV.html"><span class="hs-identifier">GHC.Utils.FV</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">FV</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Utils.FV.html#fvVarList"><span class="hs-identifier">fvVarList</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Utils.FV.html#unionFV"><span class="hs-identifier">unionFV</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Utils.FV.html#mkFVs"><span class="hs-identifier">mkFVs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-67"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="../../ghc-boot/src/GHC.LanguageExtensions.html#"><span class="hs-identifier">GHC.LanguageExtensions</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">LangExt</span></span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span>
</span><span id="line-70"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../transformers/src/Control.Monad.Trans.Class.html#"><span class="hs-identifier">Control.Monad.Trans.Class</span></a></span><span>
</span><span id="line-71"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../transformers/src/Control.Monad.Trans.Reader.html#"><span class="hs-identifier">Control.Monad.Trans.Reader</span></a></span><span>
</span><span id="line-72"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.OldList.html#partition"><span class="hs-identifier">partition</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/Data.Foldable.html#find"><span class="hs-identifier">find</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-73"></span><span>
</span><span id="line-74"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                Overview
*                                                                      *
************************************************************************

Overall plan
~~~~~~~~~~~~
1.  Convert the decls (i.e. data/newtype deriving clauses,
    plus standalone deriving) to [EarlyDerivSpec]

2.  Infer the missing contexts for the InferTheta's

3.  Add the derived bindings, generating InstInfos
-}</span><span>
</span><span id="line-90"></span><span>
</span><span id="line-91"></span><span class="hs-keyword">data</span><span> </span><span id="EarlyDerivSpec"><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-var">EarlyDerivSpec</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="InferTheta"><span class="annot"><a href="GHC.Tc.Deriv.html#InferTheta"><span class="hs-identifier hs-var">InferTheta</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpec"><span class="hs-identifier hs-type">DerivSpec</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#ThetaOrigin"><span class="hs-identifier hs-type">ThetaOrigin</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-92"></span><span>                    </span><span class="hs-glyph">|</span><span> </span><span id="GivenTheta"><span class="annot"><a href="GHC.Tc.Deriv.html#GivenTheta"><span class="hs-identifier hs-var">GivenTheta</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpec"><span class="hs-identifier hs-type">DerivSpec</span></a></span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#ThetaType"><span class="hs-identifier hs-type">ThetaType</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-93"></span><span>        </span><span class="hs-comment">-- InferTheta ds =&gt; the context for the instance should be inferred</span><span>
</span><span id="line-94"></span><span>        </span><span class="hs-comment">--      In this case ds_theta is the list of all the sets of</span><span>
</span><span id="line-95"></span><span>        </span><span class="hs-comment">--      constraints needed, such as (Eq [a], Eq a), together with a</span><span>
</span><span id="line-96"></span><span>        </span><span class="hs-comment">--      suitable CtLoc to get good error messages.</span><span>
</span><span id="line-97"></span><span>        </span><span class="hs-comment">--      The inference process is to reduce this to a</span><span>
</span><span id="line-98"></span><span>        </span><span class="hs-comment">--      simpler form (e.g. Eq a)</span><span>
</span><span id="line-99"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-100"></span><span>        </span><span class="hs-comment">-- GivenTheta ds =&gt; the exact context for the instance is supplied</span><span>
</span><span id="line-101"></span><span>        </span><span class="hs-comment">--                  by the programmer; it is ds_theta</span><span>
</span><span id="line-102"></span><span>        </span><span class="hs-comment">-- See Note [Inferring the instance context] in GHC.Tc.Deriv.Infer</span><span>
</span><span id="line-103"></span><span>
</span><span id="line-104"></span><span class="annot"><a href="GHC.Tc.Deriv.html#splitEarlyDerivSpec"><span class="hs-identifier hs-type">splitEarlyDerivSpec</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-105"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpec"><span class="hs-identifier hs-type">DerivSpec</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#ThetaOrigin"><span class="hs-identifier hs-type">ThetaOrigin</span></a></span><span class="hs-special">]</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpec"><span class="hs-identifier hs-type">DerivSpec</span></a></span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#ThetaType"><span class="hs-identifier hs-type">ThetaType</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-106"></span><span id="splitEarlyDerivSpec"><span class="annot"><span class="annottext">splitEarlyDerivSpec :: [EarlyDerivSpec]
-&gt; ([DerivSpec [ThetaOrigin]], [DerivSpec [PredType]])
</span><a href="GHC.Tc.Deriv.html#splitEarlyDerivSpec"><span class="hs-identifier hs-var hs-var">splitEarlyDerivSpec</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-107"></span><span class="annot"><a href="GHC.Tc.Deriv.html#splitEarlyDerivSpec"><span class="hs-identifier hs-var">splitEarlyDerivSpec</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.html#InferTheta"><span class="hs-identifier hs-type">InferTheta</span></a></span><span> </span><span id="local-6989586621681169017"><span class="annot"><span class="annottext">DerivSpec [ThetaOrigin]
</span><a href="#local-6989586621681169017"><span class="hs-identifier hs-var">spec</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621681169016"><span class="annot"><span class="annottext">[EarlyDerivSpec]
</span><a href="#local-6989586621681169016"><span class="hs-identifier hs-var">specs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-108"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[EarlyDerivSpec]
-&gt; ([DerivSpec [ThetaOrigin]], [DerivSpec [PredType]])
</span><a href="GHC.Tc.Deriv.html#splitEarlyDerivSpec"><span class="hs-identifier hs-var">splitEarlyDerivSpec</span></a></span><span> </span><span class="annot"><span class="annottext">[EarlyDerivSpec]
</span><a href="#local-6989586621681169016"><span class="hs-identifier hs-var">specs</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681169015"><span class="annot"><span class="annottext">[DerivSpec [ThetaOrigin]]
</span><a href="#local-6989586621681169015"><span class="hs-identifier hs-var">is</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681169014"><span class="annot"><span class="annottext">[DerivSpec [PredType]]
</span><a href="#local-6989586621681169014"><span class="hs-identifier hs-var">gs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DerivSpec [ThetaOrigin]
</span><a href="#local-6989586621681169017"><span class="hs-identifier hs-var">spec</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec [ThetaOrigin]
-&gt; [DerivSpec [ThetaOrigin]] -&gt; [DerivSpec [ThetaOrigin]]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[DerivSpec [ThetaOrigin]]
</span><a href="#local-6989586621681169015"><span class="hs-identifier hs-var">is</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[DerivSpec [PredType]]
</span><a href="#local-6989586621681169014"><span class="hs-identifier hs-var">gs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-109"></span><span class="annot"><a href="GHC.Tc.Deriv.html#splitEarlyDerivSpec"><span class="hs-identifier hs-var">splitEarlyDerivSpec</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.html#GivenTheta"><span class="hs-identifier hs-type">GivenTheta</span></a></span><span> </span><span id="local-6989586621681169013"><span class="annot"><span class="annottext">DerivSpec [PredType]
</span><a href="#local-6989586621681169013"><span class="hs-identifier hs-var">spec</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621681169012"><span class="annot"><span class="annottext">[EarlyDerivSpec]
</span><a href="#local-6989586621681169012"><span class="hs-identifier hs-var">specs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-110"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[EarlyDerivSpec]
-&gt; ([DerivSpec [ThetaOrigin]], [DerivSpec [PredType]])
</span><a href="GHC.Tc.Deriv.html#splitEarlyDerivSpec"><span class="hs-identifier hs-var">splitEarlyDerivSpec</span></a></span><span> </span><span class="annot"><span class="annottext">[EarlyDerivSpec]
</span><a href="#local-6989586621681169012"><span class="hs-identifier hs-var">specs</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681169011"><span class="annot"><span class="annottext">[DerivSpec [ThetaOrigin]]
</span><a href="#local-6989586621681169011"><span class="hs-identifier hs-var">is</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681169010"><span class="annot"><span class="annottext">[DerivSpec [PredType]]
</span><a href="#local-6989586621681169010"><span class="hs-identifier hs-var">gs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[DerivSpec [ThetaOrigin]]
</span><a href="#local-6989586621681169011"><span class="hs-identifier hs-var">is</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DerivSpec [PredType]
</span><a href="#local-6989586621681169013"><span class="hs-identifier hs-var">spec</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec [PredType]
-&gt; [DerivSpec [PredType]] -&gt; [DerivSpec [PredType]]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[DerivSpec [PredType]]
</span><a href="#local-6989586621681169010"><span class="hs-identifier hs-var">gs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-111"></span><span>
</span><span id="line-112"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621681169007"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-113"></span><span>  </span><span id="local-6989586621681168999"><span class="annot"><span class="annottext">ppr :: EarlyDerivSpec -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.html#InferTheta"><span class="hs-identifier hs-type">InferTheta</span></a></span><span> </span><span id="local-6989586621681168997"><span class="annot"><span class="annottext">DerivSpec [ThetaOrigin]
</span><a href="#local-6989586621681168997"><span class="hs-identifier hs-var">spec</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivSpec [ThetaOrigin] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec [ThetaOrigin]
</span><a href="#local-6989586621681168997"><span class="hs-identifier hs-var">spec</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;(Infer)&quot;</span></span><span>
</span><span id="line-114"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.html#GivenTheta"><span class="hs-identifier hs-type">GivenTheta</span></a></span><span> </span><span id="local-6989586621681168994"><span class="annot"><span class="annottext">DerivSpec [PredType]
</span><a href="#local-6989586621681168994"><span class="hs-identifier hs-var">spec</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivSpec [PredType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec [PredType]
</span><a href="#local-6989586621681168994"><span class="hs-identifier hs-var">spec</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;(Given)&quot;</span></span><span>
</span><span id="line-115"></span><span>
</span><span id="line-116"></span><span class="hs-comment">{-
Note [Data decl contexts]
~~~~~~~~~~~~~~~~~~~~~~~~~
Consider

        data (RealFloat a) =&gt; Complex a = !a :+ !a deriving( Read )

We will need an instance decl like:

        instance (Read a, RealFloat a) =&gt; Read (Complex a) where
          ...

The RealFloat in the context is because the read method for Complex is bound
to construct a Complex, and doing that requires that the argument type is
in RealFloat.

But this ain't true for Show, Eq, Ord, etc, since they don't construct
a Complex; they only take them apart.

Our approach: identify the offending classes, and add the data type
context to the instance decl.  The &quot;offending classes&quot; are

        Read, Enum?

FURTHER NOTE ADDED March 2002.  In fact, Haskell98 now requires that
pattern matching against a constructor from a data type with a context
gives rise to the constraints for that context -- or at least the thinned
version.  So now all classes are &quot;offending&quot;.

Note [Newtype deriving]
~~~~~~~~~~~~~~~~~~~~~~~
Consider this:
    class C a b
    instance C [a] Char
    newtype T = T Char deriving( C [a] )

Notice the free 'a' in the deriving.  We have to fill this out to
    newtype T = T Char deriving( forall a. C [a] )

And then translate it to:
    instance C [a] Char =&gt; C [a] T where ...

Note [Unused constructors and deriving clauses]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
See #3221.  Consider
   data T = T1 | T2 deriving( Show )
Are T1 and T2 unused?  Well, no: the deriving clause expands to mention
both of them.  So we gather defs/uses from deriving just like anything else.

-}</span><span>
</span><span id="line-166"></span><span>
</span><span id="line-167"></span><span class="hs-comment">-- | Stuff needed to process a datatype's `deriving` clauses</span><span>
</span><span id="line-168"></span><span class="hs-keyword">data</span><span> </span><span id="DerivInfo"><span class="annot"><a href="GHC.Tc.Deriv.html#DerivInfo"><span class="hs-identifier hs-var">DerivInfo</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="DerivInfo"><span class="annot"><a href="GHC.Tc.Deriv.html#DerivInfo"><span class="hs-identifier hs-var">DerivInfo</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="di_rep_tc"><span class="annot"><span class="annottext">DerivInfo -&gt; TyCon
</span><a href="GHC.Tc.Deriv.html#di_rep_tc"><span class="hs-identifier hs-var hs-var">di_rep_tc</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span>
</span><span id="line-169"></span><span>                             </span><span class="hs-comment">-- ^ The data tycon for normal datatypes,</span><span>
</span><span id="line-170"></span><span>                             </span><span class="hs-comment">-- or the *representation* tycon for data families</span><span>
</span><span id="line-171"></span><span>                           </span><span class="hs-special">,</span><span> </span><span id="di_scoped_tvs"><span class="annot"><span class="annottext">DerivInfo -&gt; [(Name, TyVar)]
</span><a href="GHC.Tc.Deriv.html#di_scoped_tvs"><span class="hs-identifier hs-var hs-var">di_scoped_tvs</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-172"></span><span>                             </span><span class="hs-comment">-- ^ Variables that scope over the deriving clause.</span><span>
</span><span id="line-173"></span><span>                           </span><span class="hs-special">,</span><span> </span><span id="di_clauses"><span class="annot"><span class="annottext">DerivInfo -&gt; [LHsDerivingClause GhcRn]
</span><a href="GHC.Tc.Deriv.html#di_clauses"><span class="hs-identifier hs-var hs-var">di_clauses</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Decls.html#LHsDerivingClause"><span class="hs-identifier hs-type">LHsDerivingClause</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-174"></span><span>                           </span><span class="hs-special">,</span><span> </span><span id="di_ctxt"><span class="annot"><span class="annottext">DerivInfo -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#di_ctxt"><span class="hs-identifier hs-var hs-var">di_ctxt</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span> </span><span class="hs-comment">-- ^ error context</span><span>
</span><span id="line-175"></span><span>                           </span><span class="hs-special">}</span><span>
</span><span id="line-176"></span><span>
</span><span id="line-177"></span><span class="hs-comment">{-

************************************************************************
*                                                                      *
Top-level function for \tr{derivings}
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-185"></span><span>
</span><span id="line-186"></span><span class="annot"><a href="GHC.Tc.Deriv.html#tcDeriving"><span class="hs-identifier hs-type">tcDeriving</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.html#DerivInfo"><span class="hs-identifier hs-type">DerivInfo</span></a></span><span class="hs-special">]</span><span>       </span><span class="hs-comment">-- All `deriving` clauses</span><span>
</span><span id="line-187"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Decls.html#LDerivDecl"><span class="hs-identifier hs-type">LDerivDecl</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- All stand-alone deriving declarations</span><span>
</span><span id="line-188"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.html#TcGblEnv"><span class="hs-identifier hs-type">TcGblEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Hs.Binds.html#HsValBinds"><span class="hs-identifier hs-type">HsValBinds</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-189"></span><span id="tcDeriving"><span class="annot"><span class="annottext">tcDeriving :: [DerivInfo]
-&gt; [LDerivDecl GhcRn]
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
</span><a href="GHC.Tc.Deriv.html#tcDeriving"><span class="hs-identifier hs-var hs-var">tcDeriving</span></a></span></span><span> </span><span id="local-6989586621681168988"><span class="annot"><span class="annottext">[DerivInfo]
</span><a href="#local-6989586621681168988"><span class="hs-identifier hs-var">deriv_infos</span></a></span></span><span> </span><span id="local-6989586621681168987"><span class="annot"><span class="annottext">[LDerivDecl GhcRn]
</span><a href="#local-6989586621681168987"><span class="hs-identifier hs-var">deriv_decls</span></a></span></span><span>
</span><span id="line-190"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
forall r. TcRn r -&gt; TcRn r -&gt; TcRn r
</span><a href="GHC.Tc.Utils.Monad.html#recoverM"><span class="hs-identifier hs-var">recoverM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681168985"><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681168985"><span class="hs-identifier hs-var">g</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
</span><a href="GHC.Tc.Utils.Monad.html#getGblEnv"><span class="hs-identifier hs-var">getGblEnv</span></a></span><span>
</span><span id="line-191"></span><span>                 </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681168985"><span class="hs-identifier hs-var">g</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">HsValBinds GhcRn
forall (a :: Pass) (b :: Pass).
HsValBindsLR (GhcPass a) (GhcPass b)
</span><a href="GHC.Hs.Binds.html#emptyValBindsOut"><span class="hs-identifier hs-var">emptyValBindsOut</span></a></span><span class="hs-special">)</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
 -&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn))
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-192"></span><span>    </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span class="hs-comment">-- Fish the &quot;deriving&quot;-related information out of the GHC.Tc.Utils.Env</span><span>
</span><span id="line-193"></span><span>          </span><span class="hs-comment">-- And make the necessary &quot;equations&quot;.</span><span>
</span><span id="line-194"></span><span>          </span><span id="local-6989586621681168981"><span class="annot"><span class="annottext">[EarlyDerivSpec]
</span><a href="#local-6989586621681168981"><span class="hs-identifier hs-var">early_specs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[DerivInfo] -&gt; [LDerivDecl GhcRn] -&gt; TcM [EarlyDerivSpec]
</span><a href="GHC.Tc.Deriv.html#makeDerivSpecs"><span class="hs-identifier hs-var">makeDerivSpecs</span></a></span><span> </span><span class="annot"><span class="annottext">[DerivInfo]
</span><a href="#local-6989586621681168988"><span class="hs-identifier hs-var">deriv_infos</span></a></span><span> </span><span class="annot"><span class="annottext">[LDerivDecl GhcRn]
</span><a href="#local-6989586621681168987"><span class="hs-identifier hs-var">deriv_decls</span></a></span><span>
</span><span id="line-195"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;tcDeriving&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[EarlyDerivSpec] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[EarlyDerivSpec]
</span><a href="#local-6989586621681168981"><span class="hs-identifier hs-var">early_specs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-196"></span><span>
</span><span id="line-197"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168978"><span class="annot"><span class="annottext">[DerivSpec [ThetaOrigin]]
</span><a href="#local-6989586621681168978"><span class="hs-identifier hs-var">infer_specs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168977"><span class="annot"><span class="annottext">[DerivSpec [PredType]]
</span><a href="#local-6989586621681168977"><span class="hs-identifier hs-var">given_specs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[EarlyDerivSpec]
-&gt; ([DerivSpec [ThetaOrigin]], [DerivSpec [PredType]])
</span><a href="GHC.Tc.Deriv.html#splitEarlyDerivSpec"><span class="hs-identifier hs-var">splitEarlyDerivSpec</span></a></span><span> </span><span class="annot"><span class="annottext">[EarlyDerivSpec]
</span><a href="#local-6989586621681168981"><span class="hs-identifier hs-var">early_specs</span></a></span><span>
</span><span id="line-198"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168976"><span class="annot"><span class="annottext">[([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
</span><a href="#local-6989586621681168976"><span class="hs-identifier hs-var">insts1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(DerivSpec [PredType]
 -&gt; IOEnv
      (Env TcGblEnv TcLclEnv)
      ([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name]))
-&gt; [DerivSpec [PredType]]
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     [([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec [PredType]
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
forall theta.
DerivSpec theta
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
</span><a href="GHC.Tc.Deriv.html#genInst"><span class="hs-identifier hs-var">genInst</span></a></span><span> </span><span class="annot"><span class="annottext">[DerivSpec [PredType]]
</span><a href="#local-6989586621681168977"><span class="hs-identifier hs-var">given_specs</span></a></span><span>
</span><span id="line-199"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168973"><span class="annot"><span class="annottext">[([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
</span><a href="#local-6989586621681168973"><span class="hs-identifier hs-var">insts2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(DerivSpec [ThetaOrigin]
 -&gt; IOEnv
      (Env TcGblEnv TcLclEnv)
      ([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name]))
-&gt; [DerivSpec [ThetaOrigin]]
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     [([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec [ThetaOrigin]
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
forall theta.
DerivSpec theta
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
</span><a href="GHC.Tc.Deriv.html#genInst"><span class="hs-identifier hs-var">genInst</span></a></span><span> </span><span class="annot"><span class="annottext">[DerivSpec [ThetaOrigin]]
</span><a href="#local-6989586621681168978"><span class="hs-identifier hs-var">infer_specs</span></a></span><span>
</span><span id="line-200"></span><span>
</span><span id="line-201"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168972"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168972"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -&gt; *). HasDynFlags m =&gt; m DynFlags
</span><a href="GHC.Driver.Session.html#getDynFlags"><span class="hs-identifier hs-var">getDynFlags</span></a></span><span>
</span><span id="line-202"></span><span>
</span><span id="line-203"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[[PredType] -&gt; TcM (InstInfo GhcPs)]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168970"><span class="annot"><span class="annottext">[BagDerivStuff]
</span><a href="#local-6989586621681168970"><span class="hs-identifier hs-var">deriv_stuff</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168969"><span class="annot"><span class="annottext">[[Name]]
</span><a href="#local-6989586621681168969"><span class="hs-identifier hs-var">fvs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
-&gt; ([[PredType] -&gt; TcM (InstInfo GhcPs)], [BagDerivStuff],
    [[Name]])
forall a b c. [(a, b, c)] -&gt; ([a], [b], [c])
</span><a href="../../base/src/GHC.List.html#unzip3"><span class="hs-identifier hs-var">unzip3</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
</span><a href="#local-6989586621681168976"><span class="hs-identifier hs-var">insts1</span></a></span><span> </span><span class="annot"><span class="annottext">[([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
-&gt; [([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
-&gt; [([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
</span><a href="#local-6989586621681168973"><span class="hs-identifier hs-var">insts2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-204"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168967"><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168967"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRn SrcSpan
</span><a href="GHC.Tc.Utils.Monad.html#getSrcSpanM"><span class="hs-identifier hs-var">getSrcSpanM</span></a></span><span>
</span><span id="line-205"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168965"><span class="annot"><span class="annottext">Bag (LHsBind GhcPs, LSig GhcPs)
</span><a href="#local-6989586621681168965"><span class="hs-identifier hs-var">binds</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168964"><span class="annot"><span class="annottext">Bag FamInst
</span><a href="#local-6989586621681168964"><span class="hs-identifier hs-var">famInsts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; SrcSpan
-&gt; BagDerivStuff
-&gt; (Bag (LHsBind GhcPs, LSig GhcPs), Bag FamInst)
</span><a href="GHC.Tc.Deriv.Generate.html#genAuxBinds"><span class="hs-identifier hs-var">genAuxBinds</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168972"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168967"><span class="hs-identifier hs-var">loc</span></a></span><span>
</span><span id="line-206"></span><span>                                    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[BagDerivStuff] -&gt; BagDerivStuff
forall a. [Bag a] -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionManyBags"><span class="hs-identifier hs-var">unionManyBags</span></a></span><span> </span><span class="annot"><span class="annottext">[BagDerivStuff]
</span><a href="#local-6989586621681168970"><span class="hs-identifier hs-var">deriv_stuff</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-207"></span><span>
</span><span id="line-208"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168961"><span class="annot"><span class="annottext">mk_inst_infos1 :: [[PredType] -&gt; TcM (InstInfo GhcPs)]
</span><a href="#local-6989586621681168961"><span class="hs-identifier hs-var hs-var">mk_inst_infos1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
 -&gt; [PredType] -&gt; TcM (InstInfo GhcPs))
-&gt; [([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
-&gt; [[PredType] -&gt; TcM (InstInfo GhcPs)]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
-&gt; [PredType] -&gt; TcM (InstInfo GhcPs)
forall a b c. (a, b, c) -&gt; a
</span><a href="GHC.Utils.Misc.html#fstOf3"><span class="hs-identifier hs-var">fstOf3</span></a></span><span> </span><span class="annot"><span class="annottext">[([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
</span><a href="#local-6989586621681168976"><span class="hs-identifier hs-var">insts1</span></a></span><span>
</span><span id="line-209"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168959"><span class="annot"><span class="annottext">[InstInfo GhcPs]
</span><a href="#local-6989586621681168959"><span class="hs-identifier hs-var">inst_infos1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[[PredType] -&gt; TcM (InstInfo GhcPs)]
-&gt; [DerivSpec [PredType]] -&gt; TcM [InstInfo GhcPs]
</span><a href="#local-6989586621681168958"><span class="hs-identifier hs-var">apply_inst_infos</span></a></span><span> </span><span class="annot"><span class="annottext">[[PredType] -&gt; TcM (InstInfo GhcPs)]
</span><a href="#local-6989586621681168961"><span class="hs-identifier hs-var">mk_inst_infos1</span></a></span><span> </span><span class="annot"><span class="annottext">[DerivSpec [PredType]]
</span><a href="#local-6989586621681168977"><span class="hs-identifier hs-var">given_specs</span></a></span><span>
</span><span id="line-210"></span><span>
</span><span id="line-211"></span><span>          </span><span class="hs-comment">-- We must put all the derived type family instances (from both</span><span>
</span><span id="line-212"></span><span>          </span><span class="hs-comment">-- infer_specs and given_specs) in the local instance environment</span><span>
</span><span id="line-213"></span><span>          </span><span class="hs-comment">-- before proceeding, or else simplifyInstanceContexts might</span><span>
</span><span id="line-214"></span><span>          </span><span class="hs-comment">-- get stuck if it has to reason about any of those family instances.</span><span>
</span><span id="line-215"></span><span>          </span><span class="hs-comment">-- See Note [Staging of tcDeriving]</span><span>
</span><span id="line-216"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">[FamInst]
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
forall a. [FamInst] -&gt; TcM a -&gt; TcM a
</span><a href="GHC.Tc.Instance.Family.html#tcExtendLocalFamInstEnv"><span class="hs-identifier hs-var">tcExtendLocalFamInstEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag FamInst -&gt; [FamInst]
forall a. Bag a -&gt; [a]
</span><a href="GHC.Data.Bag.html#bagToList"><span class="hs-identifier hs-var">bagToList</span></a></span><span> </span><span class="annot"><span class="annottext">Bag FamInst
</span><a href="#local-6989586621681168964"><span class="hs-identifier hs-var">famInsts</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
 -&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn))
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-217"></span><span>          </span><span class="hs-comment">-- NB: only call tcExtendLocalFamInstEnv once, as it performs</span><span>
</span><span id="line-218"></span><span>          </span><span class="hs-comment">-- validity checking for all of the family instances you give it.</span><span>
</span><span id="line-219"></span><span>          </span><span class="hs-comment">-- If the family instances have errors, calling it twice will result</span><span>
</span><span id="line-220"></span><span>          </span><span class="hs-comment">-- in duplicate error messages!</span><span>
</span><span id="line-221"></span><span>
</span><span id="line-222"></span><span>     </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-223"></span><span>        </span><span class="hs-comment">-- the stand-alone derived instances (@inst_infos1@) are used when</span><span>
</span><span id="line-224"></span><span>        </span><span class="hs-comment">-- inferring the contexts for &quot;deriving&quot; clauses' instances</span><span>
</span><span id="line-225"></span><span>        </span><span class="hs-comment">-- (@infer_specs@)</span><span>
</span><span id="line-226"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168955"><span class="annot"><span class="annottext">[DerivSpec [PredType]]
</span><a href="#local-6989586621681168955"><span class="hs-identifier hs-var">final_specs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
-&gt; TcM [DerivSpec [PredType]] -&gt; TcM [DerivSpec [PredType]]
forall a. [ClsInst] -&gt; TcM a -&gt; TcM a
</span><a href="GHC.Tc.Deriv.Utils.html#extendLocalInstEnv"><span class="hs-identifier hs-var">extendLocalInstEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(InstInfo GhcPs -&gt; ClsInst) -&gt; [InstInfo GhcPs] -&gt; [ClsInst]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">InstInfo GhcPs -&gt; ClsInst
forall a. InstInfo a -&gt; ClsInst
</span><a href="GHC.Tc.Utils.Env.html#iSpec"><span class="hs-identifier hs-var hs-var">iSpec</span></a></span><span> </span><span class="annot"><span class="annottext">[InstInfo GhcPs]
</span><a href="#local-6989586621681168959"><span class="hs-identifier hs-var">inst_infos1</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(TcM [DerivSpec [PredType]] -&gt; TcM [DerivSpec [PredType]])
-&gt; TcM [DerivSpec [PredType]] -&gt; TcM [DerivSpec [PredType]]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-227"></span><span>                         </span><span class="annot"><span class="annottext">[DerivSpec [ThetaOrigin]] -&gt; TcM [DerivSpec [PredType]]
</span><a href="GHC.Tc.Deriv.Infer.html#simplifyInstanceContexts"><span class="hs-identifier hs-var">simplifyInstanceContexts</span></a></span><span> </span><span class="annot"><span class="annottext">[DerivSpec [ThetaOrigin]]
</span><a href="#local-6989586621681168978"><span class="hs-identifier hs-var">infer_specs</span></a></span><span>
</span><span id="line-228"></span><span>
</span><span id="line-229"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168951"><span class="annot"><span class="annottext">mk_inst_infos2 :: [[PredType] -&gt; TcM (InstInfo GhcPs)]
</span><a href="#local-6989586621681168951"><span class="hs-identifier hs-var hs-var">mk_inst_infos2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
 -&gt; [PredType] -&gt; TcM (InstInfo GhcPs))
-&gt; [([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
-&gt; [[PredType] -&gt; TcM (InstInfo GhcPs)]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
-&gt; [PredType] -&gt; TcM (InstInfo GhcPs)
forall a b c. (a, b, c) -&gt; a
</span><a href="GHC.Utils.Misc.html#fstOf3"><span class="hs-identifier hs-var">fstOf3</span></a></span><span> </span><span class="annot"><span class="annottext">[([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])]
</span><a href="#local-6989586621681168973"><span class="hs-identifier hs-var">insts2</span></a></span><span>
</span><span id="line-230"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168950"><span class="annot"><span class="annottext">[InstInfo GhcPs]
</span><a href="#local-6989586621681168950"><span class="hs-identifier hs-var">inst_infos2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[[PredType] -&gt; TcM (InstInfo GhcPs)]
-&gt; [DerivSpec [PredType]] -&gt; TcM [InstInfo GhcPs]
</span><a href="#local-6989586621681168958"><span class="hs-identifier hs-var">apply_inst_infos</span></a></span><span> </span><span class="annot"><span class="annottext">[[PredType] -&gt; TcM (InstInfo GhcPs)]
</span><a href="#local-6989586621681168951"><span class="hs-identifier hs-var">mk_inst_infos2</span></a></span><span> </span><span class="annot"><span class="annottext">[DerivSpec [PredType]]
</span><a href="#local-6989586621681168955"><span class="hs-identifier hs-var">final_specs</span></a></span><span>
</span><span id="line-231"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168949"><span class="annot"><span class="annottext">inst_infos :: [InstInfo GhcPs]
</span><a href="#local-6989586621681168949"><span class="hs-identifier hs-var hs-var">inst_infos</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[InstInfo GhcPs]
</span><a href="#local-6989586621681168959"><span class="hs-identifier hs-var">inst_infos1</span></a></span><span> </span><span class="annot"><span class="annottext">[InstInfo GhcPs] -&gt; [InstInfo GhcPs] -&gt; [InstInfo GhcPs]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[InstInfo GhcPs]
</span><a href="#local-6989586621681168950"><span class="hs-identifier hs-var">inst_infos2</span></a></span><span>
</span><span id="line-232"></span><span>
</span><span id="line-233"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168948"><span class="annot"><span class="annottext">Bag (InstInfo GhcRn)
</span><a href="#local-6989586621681168948"><span class="hs-identifier hs-var">inst_info</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168947"><span class="annot"><span class="annottext">HsValBinds GhcRn
</span><a href="#local-6989586621681168947"><span class="hs-identifier hs-var">rn_binds</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168946"><span class="annot"><span class="annottext">DefUses
</span><a href="#local-6989586621681168946"><span class="hs-identifier hs-var">rn_dus</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[InstInfo GhcPs]
-&gt; Bag (LHsBind GhcPs, LSig GhcPs)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
</span><a href="GHC.Tc.Deriv.html#renameDeriv"><span class="hs-identifier hs-var">renameDeriv</span></a></span><span> </span><span class="annot"><span class="annottext">[InstInfo GhcPs]
</span><a href="#local-6989586621681168949"><span class="hs-identifier hs-var">inst_infos</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (LHsBind GhcPs, LSig GhcPs)
</span><a href="#local-6989586621681168965"><span class="hs-identifier hs-var">binds</span></a></span><span>
</span><span id="line-234"></span><span>
</span><span id="line-235"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; TcRn () -&gt; TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn) -&gt; Bool
forall a. Bag a -&gt; Bool
</span><a href="GHC.Data.Bag.html#isEmptyBag"><span class="hs-identifier hs-var">isEmptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn)
</span><a href="#local-6989586621681168948"><span class="hs-identifier hs-var">inst_info</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; TcRn ()) -&gt; TcRn () -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-236"></span><span>             </span><span class="annot"><span class="annottext">IO () -&gt; TcRn ()
forall (m :: * -&gt; *) a. MonadIO m =&gt; IO a -&gt; m a
</span><a href="../../base/src/Control.Monad.IO.Class.html#liftIO"><span class="hs-identifier hs-var">liftIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; DumpFlag -&gt; String -&gt; DumpFormat -&gt; SDoc -&gt; IO ()
</span><a href="GHC.Utils.Error.html#dumpIfSet_dyn"><span class="hs-identifier hs-var">dumpIfSet_dyn</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168972"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">DumpFlag
</span><a href="GHC.Driver.Flags.html#Opt_D_dump_deriv"><span class="hs-identifier hs-var">Opt_D_dump_deriv</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Derived instances&quot;</span></span><span>
</span><span id="line-237"></span><span>                        </span><span class="annot"><span class="annottext">DumpFormat
</span><a href="GHC.Utils.Error.html#FormatHaskell"><span class="hs-identifier hs-var">FormatHaskell</span></a></span><span>
</span><span id="line-238"></span><span>                        </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn) -&gt; HsValBinds GhcRn -&gt; Bag FamInst -&gt; SDoc
</span><a href="#local-6989586621681168938"><span class="hs-identifier hs-var">ddump_deriving</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn)
</span><a href="#local-6989586621681168948"><span class="hs-identifier hs-var">inst_info</span></a></span><span> </span><span class="annot"><span class="annottext">HsValBinds GhcRn
</span><a href="#local-6989586621681168947"><span class="hs-identifier hs-var">rn_binds</span></a></span><span> </span><span class="annot"><span class="annottext">Bag FamInst
</span><a href="#local-6989586621681168964"><span class="hs-identifier hs-var">famInsts</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-239"></span><span>
</span><span id="line-240"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168937"><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681168937"><span class="hs-identifier hs-var">gbl_env</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
-&gt; TcRnIf TcGblEnv TcLclEnv TcGblEnv
-&gt; TcRnIf TcGblEnv TcLclEnv TcGblEnv
forall a. [ClsInst] -&gt; TcM a -&gt; TcM a
</span><a href="GHC.Tc.Utils.Instantiate.html#tcExtendLocalInstEnv"><span class="hs-identifier hs-var">tcExtendLocalInstEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(InstInfo GhcRn -&gt; ClsInst) -&gt; [InstInfo GhcRn] -&gt; [ClsInst]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">InstInfo GhcRn -&gt; ClsInst
forall a. InstInfo a -&gt; ClsInst
</span><a href="GHC.Tc.Utils.Env.html#iSpec"><span class="hs-identifier hs-var hs-var">iSpec</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn) -&gt; [InstInfo GhcRn]
forall a. Bag a -&gt; [a]
</span><a href="GHC.Data.Bag.html#bagToList"><span class="hs-identifier hs-var">bagToList</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn)
</span><a href="#local-6989586621681168948"><span class="hs-identifier hs-var">inst_info</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-241"></span><span>                                          </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
</span><a href="GHC.Tc.Utils.Monad.html#getGblEnv"><span class="hs-identifier hs-var">getGblEnv</span></a></span><span>
</span><span id="line-242"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168935"><span class="annot"><span class="annottext">all_dus :: DefUses
</span><a href="#local-6989586621681168935"><span class="hs-identifier hs-var hs-var">all_dus</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DefUses
</span><a href="#local-6989586621681168946"><span class="hs-identifier hs-var">rn_dus</span></a></span><span> </span><span class="annot"><span class="annottext">DefUses -&gt; DefUses -&gt; DefUses
</span><a href="GHC.Types.Name.Set.html#plusDU"><span class="hs-operator hs-var">`plusDU`</span></a></span><span> </span><span class="annot"><span class="annottext">Uses -&gt; DefUses
</span><a href="GHC.Types.Name.Set.html#usesOnly"><span class="hs-identifier hs-var">usesOnly</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Name] -&gt; Uses
</span><a href="GHC.Types.Name.Set.html#mkFVs"><span class="hs-identifier hs-var">NameSet.mkFVs</span></a></span><span> </span><span class="annot"><span class="annottext">([Name] -&gt; Uses) -&gt; [Name] -&gt; Uses
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[[Name]] -&gt; [Name]
forall (t :: * -&gt; *) a. Foldable t =&gt; t [a] -&gt; [a]
</span><a href="../../base/src/Data.Foldable.html#concat"><span class="hs-identifier hs-var">concat</span></a></span><span> </span><span class="annot"><span class="annottext">[[Name]]
</span><a href="#local-6989586621681168969"><span class="hs-identifier hs-var">fvs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-243"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
-&gt; TcM (TcGblEnv, Bag (InstInfo GhcRn), HsValBinds GhcRn)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcGblEnv -&gt; DefUses -&gt; TcGblEnv
</span><a href="GHC.Rename.Module.html#addTcgDUs"><span class="hs-identifier hs-var">addTcgDUs</span></a></span><span> </span><span class="annot"><span class="annottext">TcGblEnv
</span><a href="#local-6989586621681168937"><span class="hs-identifier hs-var">gbl_env</span></a></span><span> </span><span class="annot"><span class="annottext">DefUses
</span><a href="#local-6989586621681168935"><span class="hs-identifier hs-var">all_dus</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn)
</span><a href="#local-6989586621681168948"><span class="hs-identifier hs-var">inst_info</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">HsValBinds GhcRn
</span><a href="#local-6989586621681168947"><span class="hs-identifier hs-var">rn_binds</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-244"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-245"></span><span>    </span><span class="annot"><a href="#local-6989586621681168938"><span class="hs-identifier hs-type">ddump_deriving</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Hs.Binds.html#HsValBinds"><span class="hs-identifier hs-type">HsValBinds</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span>
</span><span id="line-246"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span>             </span><span class="hs-comment">-- ^ Rep type family instances</span><span>
</span><span id="line-247"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-248"></span><span>    </span><span id="local-6989586621681168938"><span class="annot"><span class="annottext">ddump_deriving :: Bag (InstInfo GhcRn) -&gt; HsValBinds GhcRn -&gt; Bag FamInst -&gt; SDoc
</span><a href="#local-6989586621681168938"><span class="hs-identifier hs-var hs-var">ddump_deriving</span></a></span></span><span> </span><span id="local-6989586621681168930"><span class="annot"><span class="annottext">Bag (InstInfo GhcRn)
</span><a href="#local-6989586621681168930"><span class="hs-identifier hs-var">inst_infos</span></a></span></span><span> </span><span id="local-6989586621681168929"><span class="annot"><span class="annottext">HsValBinds GhcRn
</span><a href="#local-6989586621681168929"><span class="hs-identifier hs-var">extra_binds</span></a></span></span><span> </span><span id="local-6989586621681168928"><span class="annot"><span class="annottext">Bag FamInst
</span><a href="#local-6989586621681168928"><span class="hs-identifier hs-var">repFamInsts</span></a></span></span><span>
</span><span id="line-249"></span><span>      </span><span class="hs-glyph">=</span><span>    </span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Derived class instances:&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-250"></span><span>              </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(InstInfo GhcRn -&gt; SDoc) -&gt; [InstInfo GhcRn] -&gt; [SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621681168925"><span class="annot"><span class="annottext">InstInfo GhcRn
</span><a href="#local-6989586621681168925"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">InstInfo GhcRn -&gt; SDoc
forall (a :: Pass).
OutputableBndrId a =&gt;
InstInfo (GhcPass a) -&gt; SDoc
</span><a href="GHC.Tc.Utils.Env.html#pprInstInfoDetails"><span class="hs-identifier hs-var">pprInstInfoDetails</span></a></span><span> </span><span class="annot"><span class="annottext">InstInfo GhcRn
</span><a href="#local-6989586621681168925"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn) -&gt; [InstInfo GhcRn]
forall a. Bag a -&gt; [a]
</span><a href="GHC.Data.Bag.html#bagToList"><span class="hs-identifier hs-var">bagToList</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (InstInfo GhcRn)
</span><a href="#local-6989586621681168930"><span class="hs-identifier hs-var">inst_infos</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-251"></span><span>                 </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">HsValBinds GhcRn -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">HsValBinds GhcRn
</span><a href="#local-6989586621681168929"><span class="hs-identifier hs-var">extra_binds</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-252"></span><span>        </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; SDoc
</span><a href="#local-6989586621681168922"><span class="hs-identifier hs-var">hangP</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Derived type family instances:&quot;</span></span><span>
</span><span id="line-253"></span><span>             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(FamInst -&gt; SDoc) -&gt; [FamInst] -&gt; [SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#pprRepTy"><span class="hs-identifier hs-var">pprRepTy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag FamInst -&gt; [FamInst]
forall a. Bag a -&gt; [a]
</span><a href="GHC.Data.Bag.html#bagToList"><span class="hs-identifier hs-var">bagToList</span></a></span><span> </span><span class="annot"><span class="annottext">Bag FamInst
</span><a href="#local-6989586621681168928"><span class="hs-identifier hs-var">repFamInsts</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-254"></span><span>
</span><span id="line-255"></span><span>    </span><span id="local-6989586621681168922"><span class="annot"><span class="annottext">hangP :: String -&gt; SDoc -&gt; SDoc
</span><a href="#local-6989586621681168922"><span class="hs-identifier hs-var hs-var">hangP</span></a></span></span><span> </span><span id="local-6989586621681168920"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621681168920"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621681168919"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168919"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PtrString -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ptext"><span class="hs-identifier hs-var">ptext</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; PtrString
</span><a href="GHC.Data.FastString.html#sLit"><span class="hs-identifier hs-var">sLit</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621681168920"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168919"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-256"></span><span>
</span><span id="line-257"></span><span>    </span><span class="hs-comment">-- Apply the suspended computations given by genInst calls.</span><span>
</span><span id="line-258"></span><span>    </span><span class="hs-comment">-- See Note [Staging of tcDeriving]</span><span>
</span><span id="line-259"></span><span>    </span><span class="annot"><a href="#local-6989586621681168958"><span class="hs-identifier hs-type">apply_inst_infos</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#ThetaType"><span class="hs-identifier hs-type">ThetaType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcPs"><span class="hs-identifier hs-type">GhcPs</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-260"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpec"><span class="hs-identifier hs-type">DerivSpec</span></a></span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#ThetaType"><span class="hs-identifier hs-type">ThetaType</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcPs"><span class="hs-identifier hs-type">GhcPs</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-261"></span><span>    </span><span id="local-6989586621681168958"><span class="annot"><span class="annottext">apply_inst_infos :: [[PredType] -&gt; TcM (InstInfo GhcPs)]
-&gt; [DerivSpec [PredType]] -&gt; TcM [InstInfo GhcPs]
</span><a href="#local-6989586621681168958"><span class="hs-identifier hs-var hs-var">apply_inst_infos</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(([PredType] -&gt; TcM (InstInfo GhcPs))
 -&gt; DerivSpec [PredType] -&gt; TcM (InstInfo GhcPs))
-&gt; [[PredType] -&gt; TcM (InstInfo GhcPs)]
-&gt; [DerivSpec [PredType]]
-&gt; TcM [InstInfo GhcPs]
forall (m :: * -&gt; *) a b c.
Applicative m =&gt;
(a -&gt; b -&gt; m c) -&gt; [a] -&gt; [b] -&gt; m [c]
</span><a href="../../base/src/Control.Monad.html#zipWithM"><span class="hs-identifier hs-var">zipWithM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621681168915"><span class="annot"><span class="annottext">[PredType] -&gt; TcM (InstInfo GhcPs)
</span><a href="#local-6989586621681168915"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621681168914"><span class="annot"><span class="annottext">DerivSpec [PredType]
</span><a href="#local-6989586621681168914"><span class="hs-identifier hs-var">ds</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; TcM (InstInfo GhcPs)
</span><a href="#local-6989586621681168915"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DerivSpec [PredType] -&gt; [PredType]
forall theta. DerivSpec theta -&gt; theta
</span><a href="GHC.Tc.Deriv.Utils.html#ds_theta"><span class="hs-identifier hs-var hs-var">ds_theta</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec [PredType]
</span><a href="#local-6989586621681168914"><span class="hs-identifier hs-var">ds</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-262"></span><span>
</span><span id="line-263"></span><span class="hs-comment">-- Prints the representable type family instance</span><span>
</span><span id="line-264"></span><span class="annot"><a href="GHC.Tc.Deriv.html#pprRepTy"><span class="hs-identifier hs-type">pprRepTy</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-265"></span><span id="pprRepTy"><span class="annot"><span class="annottext">pprRepTy :: FamInst -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#pprRepTy"><span class="hs-identifier hs-var hs-var">pprRepTy</span></a></span></span><span> </span><span id="local-6989586621681168912"><span class="annot"><span class="annottext">fi :: FamInst
</span><a href="#local-6989586621681168912"><span class="hs-identifier hs-var">fi</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInst"><span class="hs-identifier hs-type">FamInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fi_tys :: FamInst -&gt; [PredType]
</span><a href="GHC.Core.FamInstEnv.html#fi_tys"><span class="hs-identifier hs-var">fi_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168909"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168909"><span class="hs-identifier hs-var">lhs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-266"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;type&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">PredType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [PredType] -&gt; PredType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInst -&gt; TyCon
</span><a href="GHC.Core.FamInstEnv.html#famInstTyCon"><span class="hs-identifier hs-var">famInstTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681168912"><span class="hs-identifier hs-var">fi</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168909"><span class="hs-identifier hs-var">lhs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-267"></span><span>      </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#equals"><span class="hs-identifier hs-var">equals</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">PredType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168905"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-268"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621681168905"><span class="annot"><span class="annottext">rhs :: PredType
</span><a href="#local-6989586621681168905"><span class="hs-identifier hs-var hs-var">rhs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; PredType
</span><a href="GHC.Core.FamInstEnv.html#famInstRHS"><span class="hs-identifier hs-var">famInstRHS</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst
</span><a href="#local-6989586621681168912"><span class="hs-identifier hs-var">fi</span></a></span><span>
</span><span id="line-269"></span><span>
</span><span id="line-270"></span><span class="annot"><a href="GHC.Tc.Deriv.html#renameDeriv"><span class="hs-identifier hs-type">renameDeriv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcPs"><span class="hs-identifier hs-type">GhcPs</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-271"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Binds.html#LHsBind"><span class="hs-identifier hs-type">LHsBind</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcPs"><span class="hs-identifier hs-type">GhcPs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Hs.Binds.html#LSig"><span class="hs-identifier hs-type">LSig</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcPs"><span class="hs-identifier hs-type">GhcPs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-272"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Bag.html#Bag"><span class="hs-identifier hs-type">Bag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Hs.Binds.html#HsValBinds"><span class="hs-identifier hs-type">HsValBinds</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Name.Set.html#DefUses"><span class="hs-identifier hs-type">DefUses</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-273"></span><span id="renameDeriv"><span class="annot"><span class="annottext">renameDeriv :: [InstInfo GhcPs]
-&gt; Bag (LHsBind GhcPs, LSig GhcPs)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
</span><a href="GHC.Tc.Deriv.html#renameDeriv"><span class="hs-identifier hs-var hs-var">renameDeriv</span></a></span></span><span> </span><span id="local-6989586621681168903"><span class="annot"><span class="annottext">[InstInfo GhcPs]
</span><a href="#local-6989586621681168903"><span class="hs-identifier hs-var">inst_infos</span></a></span></span><span> </span><span id="local-6989586621681168902"><span class="annot"><span class="annottext">Bag (LHsBind GhcPs, LSig GhcPs)
</span><a href="#local-6989586621681168902"><span class="hs-identifier hs-var">bagBinds</span></a></span></span><span>
</span><span id="line-274"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a. TcRn a -&gt; TcRn a
</span><a href="GHC.Tc.Utils.Monad.html#discardWarnings"><span class="hs-identifier hs-var">discardWarnings</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
 -&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses))
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-275"></span><span>    </span><span class="hs-comment">-- Discard warnings about unused bindings etc</span><span>
</span><span id="line-276"></span><span>    </span><span class="annot"><span class="annottext">Extension
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall gbl lcl a. Extension -&gt; TcRnIf gbl lcl a -&gt; TcRnIf gbl lcl a
</span><a href="GHC.Tc.Utils.Monad.html#setXOptM"><span class="hs-identifier hs-var">setXOptM</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#EmptyCase"><span class="hs-identifier hs-var">LangExt.EmptyCase</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
 -&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses))
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-277"></span><span>    </span><span class="hs-comment">-- Derived decls (for empty types) can have</span><span>
</span><span id="line-278"></span><span>    </span><span class="hs-comment">--    case x of {}</span><span>
</span><span id="line-279"></span><span>    </span><span class="annot"><span class="annottext">Extension
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall gbl lcl a. Extension -&gt; TcRnIf gbl lcl a -&gt; TcRnIf gbl lcl a
</span><a href="GHC.Tc.Utils.Monad.html#setXOptM"><span class="hs-identifier hs-var">setXOptM</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#ScopedTypeVariables"><span class="hs-identifier hs-var">LangExt.ScopedTypeVariables</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
 -&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses))
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-280"></span><span>    </span><span class="annot"><span class="annottext">Extension
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall gbl lcl a. Extension -&gt; TcRnIf gbl lcl a -&gt; TcRnIf gbl lcl a
</span><a href="GHC.Tc.Utils.Monad.html#setXOptM"><span class="hs-identifier hs-var">setXOptM</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#KindSignatures"><span class="hs-identifier hs-var">LangExt.KindSignatures</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
 -&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses))
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-281"></span><span>    </span><span class="hs-comment">-- Derived decls (for newtype-deriving) can use ScopedTypeVariables &amp;</span><span>
</span><span id="line-282"></span><span>    </span><span class="hs-comment">-- KindSignatures</span><span>
</span><span id="line-283"></span><span>    </span><span class="annot"><span class="annottext">Extension
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall gbl lcl a. Extension -&gt; TcRnIf gbl lcl a -&gt; TcRnIf gbl lcl a
</span><a href="GHC.Tc.Utils.Monad.html#setXOptM"><span class="hs-identifier hs-var">setXOptM</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#TypeApplications"><span class="hs-identifier hs-var">LangExt.TypeApplications</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
 -&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses))
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-284"></span><span>    </span><span class="hs-comment">-- GND/DerivingVia uses TypeApplications in generated code</span><span>
</span><span id="line-285"></span><span>    </span><span class="hs-comment">-- (See Note [Newtype-deriving instances] in GHC.Tc.Deriv.Generate)</span><span>
</span><span id="line-286"></span><span>    </span><span class="annot"><span class="annottext">Extension
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall gbl lcl a. Extension -&gt; TcRnIf gbl lcl a -&gt; TcRnIf gbl lcl a
</span><a href="GHC.Tc.Utils.Monad.html#unsetXOptM"><span class="hs-identifier hs-var">unsetXOptM</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#RebindableSyntax"><span class="hs-identifier hs-var">LangExt.RebindableSyntax</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
 -&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses))
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-287"></span><span>    </span><span class="hs-comment">-- See Note [Avoid RebindableSyntax when deriving]</span><span>
</span><span id="line-288"></span><span>    </span><span class="annot"><span class="annottext">Extension
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall gbl lcl a. Extension -&gt; TcRnIf gbl lcl a -&gt; TcRnIf gbl lcl a
</span><a href="GHC.Tc.Utils.Monad.html#setXOptM"><span class="hs-identifier hs-var">setXOptM</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#TemplateHaskellQuotes"><span class="hs-identifier hs-var">LangExt.TemplateHaskellQuotes</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
 -&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses))
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-289"></span><span>    </span><span class="hs-comment">-- DeriveLift makes uses of quotes</span><span>
</span><span id="line-290"></span><span>    </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span>
</span><span id="line-291"></span><span>        </span><span class="hs-comment">-- Bring the extra deriving stuff into scope</span><span>
</span><span id="line-292"></span><span>        </span><span class="hs-comment">-- before renaming the instances themselves</span><span>
</span><span id="line-293"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;rnd&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(InstInfo GhcPs -&gt; SDoc) -&gt; [InstInfo GhcPs] -&gt; [SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621681168892"><span class="annot"><span class="annottext">InstInfo GhcPs
</span><a href="#local-6989586621681168892"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">InstInfo GhcPs -&gt; SDoc
forall (a :: Pass).
OutputableBndrId a =&gt;
InstInfo (GhcPass a) -&gt; SDoc
</span><a href="GHC.Tc.Utils.Env.html#pprInstInfoDetails"><span class="hs-identifier hs-var">pprInstInfoDetails</span></a></span><span> </span><span class="annot"><span class="annottext">InstInfo GhcPs
</span><a href="#local-6989586621681168892"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[InstInfo GhcPs]
</span><a href="#local-6989586621681168903"><span class="hs-identifier hs-var">inst_infos</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-294"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168891"><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168891"><span class="hs-identifier hs-var">aux_binds</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168890"><span class="annot"><span class="annottext">Bag (LSig GhcPs)
</span><a href="#local-6989586621681168890"><span class="hs-identifier hs-var">aux_sigs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">((LHsBind GhcPs, LSig GhcPs)
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcPs, LSig GhcPs))
-&gt; Bag (LHsBind GhcPs, LSig GhcPs)
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv) (Bag (LHsBind GhcPs), Bag (LSig GhcPs))
forall (m :: * -&gt; *) a b c.
Monad m =&gt;
(a -&gt; m (b, c)) -&gt; Bag a -&gt; m (Bag b, Bag c)
</span><a href="GHC.Data.Bag.html#mapAndUnzipBagM"><span class="hs-identifier hs-var">mapAndUnzipBagM</span></a></span><span> </span><span class="annot"><span class="annottext">(LHsBind GhcPs, LSig GhcPs)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (LHsBind GhcPs, LSig GhcPs)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (LHsBind GhcPs, LSig GhcPs)
</span><a href="#local-6989586621681168902"><span class="hs-identifier hs-var">bagBinds</span></a></span><span>
</span><span id="line-295"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168888"><span class="annot"><span class="annottext">aux_val_binds :: HsValBindsLR GhcPs GhcPs
</span><a href="#local-6989586621681168888"><span class="hs-identifier hs-var hs-var">aux_val_binds</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">XValBinds GhcPs GhcPs
-&gt; Bag (LHsBind GhcPs) -&gt; [LSig GhcPs] -&gt; HsValBindsLR GhcPs GhcPs
forall idL idR.
XValBinds idL idR
-&gt; LHsBindsLR idL idR -&gt; [LSig idR] -&gt; HsValBindsLR idL idR
</span><a href="GHC.Hs.Binds.html#ValBinds"><span class="hs-identifier hs-var">ValBinds</span></a></span><span> </span><span class="annot"><span class="annottext">NoExtField
XValBinds GhcPs GhcPs
</span><a href="GHC.Hs.Extension.html#noExtField"><span class="hs-identifier hs-var">noExtField</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168891"><span class="hs-identifier hs-var">aux_binds</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (LSig GhcPs) -&gt; [LSig GhcPs]
forall a. Bag a -&gt; [a]
</span><a href="GHC.Data.Bag.html#bagToList"><span class="hs-identifier hs-var">bagToList</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (LSig GhcPs)
</span><a href="#local-6989586621681168890"><span class="hs-identifier hs-var">aux_sigs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-296"></span><span>        </span><span class="hs-comment">-- Importantly, we use rnLocalValBindsLHS, not rnTopBindsLHS, to rename</span><span>
</span><span id="line-297"></span><span>        </span><span class="hs-comment">-- auxiliary bindings as if they were defined locally.</span><span>
</span><span id="line-298"></span><span>        </span><span class="hs-comment">-- See Note [Auxiliary binders] in GHC.Tc.Deriv.Generate.</span><span>
</span><span id="line-299"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168885"><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168885"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168884"><span class="annot"><span class="annottext">HsValBindsLR GhcRn GhcPs
</span><a href="#local-6989586621681168884"><span class="hs-identifier hs-var">rn_aux_lhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MiniFixityEnv
-&gt; HsValBindsLR GhcPs GhcPs
-&gt; RnM ([Name], HsValBindsLR GhcRn GhcPs)
</span><a href="GHC.Rename.Bind.html#rnLocalValBindsLHS"><span class="hs-identifier hs-var">rnLocalValBindsLHS</span></a></span><span> </span><span class="annot"><span class="annottext">MiniFixityEnv
forall a. FastStringEnv a
</span><a href="GHC.Data.FastString.Env.html#emptyFsEnv"><span class="hs-identifier hs-var">emptyFsEnv</span></a></span><span> </span><span class="annot"><span class="annottext">HsValBindsLR GhcPs GhcPs
</span><a href="#local-6989586621681168888"><span class="hs-identifier hs-var">aux_val_binds</span></a></span><span>
</span><span id="line-300"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">[Name]
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a. [Name] -&gt; RnM a -&gt; RnM a
</span><a href="GHC.Rename.Utils.html#bindLocalNames"><span class="hs-identifier hs-var">bindLocalNames</span></a></span><span> </span><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168885"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
 -&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses))
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-301"></span><span>    </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168880"><span class="annot"><span class="annottext">HsValBinds GhcRn
</span><a href="#local-6989586621681168880"><span class="hs-identifier hs-var">rn_aux</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168879"><span class="annot"><span class="annottext">DefUses
</span><a href="#local-6989586621681168879"><span class="hs-identifier hs-var">dus_aux</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Uses -&gt; HsValBindsLR GhcRn GhcPs -&gt; RnM (HsValBinds GhcRn, DefUses)
</span><a href="GHC.Rename.Bind.html#rnLocalValBindsRHS"><span class="hs-identifier hs-var">rnLocalValBindsRHS</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Name] -&gt; Uses
</span><a href="GHC.Types.Name.Set.html#mkNameSet"><span class="hs-identifier hs-var">mkNameSet</span></a></span><span> </span><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168885"><span class="hs-identifier hs-var">bndrs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">HsValBindsLR GhcRn GhcPs
</span><a href="#local-6989586621681168884"><span class="hs-identifier hs-var">rn_aux_lhs</span></a></span><span>
</span><span id="line-302"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168876"><span class="annot"><span class="annottext">[InstInfo GhcRn]
</span><a href="#local-6989586621681168876"><span class="hs-identifier hs-var">rn_inst_infos</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168875"><span class="annot"><span class="annottext">[Uses]
</span><a href="#local-6989586621681168875"><span class="hs-identifier hs-var">fvs_insts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(InstInfo GhcPs
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (InstInfo GhcRn, Uses))
-&gt; [InstInfo GhcPs]
-&gt; IOEnv (Env TcGblEnv TcLclEnv) ([InstInfo GhcRn], [Uses])
forall (m :: * -&gt; *) a b c.
Applicative m =&gt;
(a -&gt; m (b, c)) -&gt; [a] -&gt; m ([b], [c])
</span><a href="../../base/src/Control.Monad.html#mapAndUnzipM"><span class="hs-identifier hs-var">mapAndUnzipM</span></a></span><span> </span><span class="annot"><span class="annottext">InstInfo GhcPs
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (InstInfo GhcRn, Uses)
</span><a href="#local-6989586621681168873"><span class="hs-identifier hs-var">rn_inst_info</span></a></span><span> </span><span class="annot"><span class="annottext">[InstInfo GhcPs]
</span><a href="#local-6989586621681168903"><span class="hs-identifier hs-var">inst_infos</span></a></span><span>
</span><span id="line-303"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
-&gt; TcM (Bag (InstInfo GhcRn), HsValBinds GhcRn, DefUses)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[InstInfo GhcRn] -&gt; Bag (InstInfo GhcRn)
forall a. [a] -&gt; Bag a
</span><a href="GHC.Data.Bag.html#listToBag"><span class="hs-identifier hs-var">listToBag</span></a></span><span> </span><span class="annot"><span class="annottext">[InstInfo GhcRn]
</span><a href="#local-6989586621681168876"><span class="hs-identifier hs-var">rn_inst_infos</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">HsValBinds GhcRn
</span><a href="#local-6989586621681168880"><span class="hs-identifier hs-var">rn_aux</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-304"></span><span>                  </span><span class="annot"><span class="annottext">DefUses
</span><a href="#local-6989586621681168879"><span class="hs-identifier hs-var">dus_aux</span></a></span><span> </span><span class="annot"><span class="annottext">DefUses -&gt; DefUses -&gt; DefUses
</span><a href="GHC.Types.Name.Set.html#plusDU"><span class="hs-operator hs-var">`plusDU`</span></a></span><span> </span><span class="annot"><span class="annottext">Uses -&gt; DefUses
</span><a href="GHC.Types.Name.Set.html#usesOnly"><span class="hs-identifier hs-var">usesOnly</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Uses] -&gt; Uses
</span><a href="GHC.Types.Name.Set.html#plusFVs"><span class="hs-identifier hs-var">plusFVs</span></a></span><span> </span><span class="annot"><span class="annottext">[Uses]
</span><a href="#local-6989586621681168875"><span class="hs-identifier hs-var">fvs_insts</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-305"></span><span>
</span><span id="line-306"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-307"></span><span>    </span><span class="annot"><a href="#local-6989586621681168873"><span class="hs-identifier hs-type">rn_inst_info</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcPs"><span class="hs-identifier hs-type">GhcPs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Name.Set.html#FreeVars"><span class="hs-identifier hs-type">FreeVars</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-308"></span><span>    </span><span id="local-6989586621681168873"><span class="annot"><span class="annottext">rn_inst_info :: InstInfo GhcPs
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (InstInfo GhcRn, Uses)
</span><a href="#local-6989586621681168873"><span class="hs-identifier hs-var hs-var">rn_inst_info</span></a></span></span><span>
</span><span id="line-309"></span><span>      </span><span id="local-6989586621681168869"><span class="annot"><span class="annottext">inst_info :: InstInfo GhcPs
</span><a href="#local-6989586621681168869"><span class="hs-identifier hs-var">inst_info</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">iSpec :: forall a. InstInfo a -&gt; ClsInst
</span><a href="GHC.Tc.Utils.Env.html#iSpec"><span class="hs-identifier hs-var">iSpec</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168867"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621681168867"><span class="hs-identifier hs-var">inst</span></a></span></span><span>
</span><span id="line-310"></span><span>                          </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">iBinds :: forall a. InstInfo a -&gt; InstBindings a
</span><a href="GHC.Tc.Utils.Env.html#iBinds"><span class="hs-identifier hs-var">iBinds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstBindings"><span class="hs-identifier hs-type">InstBindings</span></a></span><span>
</span><span id="line-311"></span><span>                            </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ib_binds :: forall a. InstBindings a -&gt; LHsBinds a
</span><a href="GHC.Tc.Utils.Env.html#ib_binds"><span class="hs-identifier hs-var">ib_binds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168863"><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168863"><span class="hs-identifier hs-var">binds</span></a></span></span><span>
</span><span id="line-312"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_tyvars :: forall a. InstBindings a -&gt; [Name]
</span><a href="GHC.Tc.Utils.Env.html#ib_tyvars"><span class="hs-identifier hs-var">ib_tyvars</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168861"><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168861"><span class="hs-identifier hs-var">tyvars</span></a></span></span><span>
</span><span id="line-313"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_pragmas :: forall a. InstBindings a -&gt; [LSig a]
</span><a href="GHC.Tc.Utils.Env.html#ib_pragmas"><span class="hs-identifier hs-var">ib_pragmas</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168859"><span class="annot"><span class="annottext">[LSig GhcPs]
</span><a href="#local-6989586621681168859"><span class="hs-identifier hs-var">sigs</span></a></span></span><span>
</span><span id="line-314"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_extensions :: forall a. InstBindings a -&gt; [Extension]
</span><a href="GHC.Tc.Utils.Env.html#ib_extensions"><span class="hs-identifier hs-var">ib_extensions</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168857"><span class="annot"><span class="annottext">[Extension]
</span><a href="#local-6989586621681168857"><span class="hs-identifier hs-var">exts</span></a></span></span><span> </span><span class="hs-comment">-- Only for type-checking</span><span>
</span><span id="line-315"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_derived :: forall a. InstBindings a -&gt; Bool
</span><a href="GHC.Tc.Utils.Env.html#ib_derived"><span class="hs-identifier hs-var">ib_derived</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168855"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168855"><span class="hs-identifier hs-var">sa</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-316"></span><span>        </span><span class="hs-glyph">=</span><span>  </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168854"><span class="annot"><span class="annottext">LHsBinds GhcRn
</span><a href="#local-6989586621681168854"><span class="hs-identifier hs-var">rn_binds</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168853"><span class="annot"><span class="annottext">[LSig GhcRn]
</span><a href="#local-6989586621681168853"><span class="hs-identifier hs-var">rn_sigs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168852"><span class="annot"><span class="annottext">Uses
</span><a href="#local-6989586621681168852"><span class="hs-identifier hs-var">fvs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Bool
-&gt; Name
-&gt; [Name]
-&gt; Bag (LHsBind GhcPs)
-&gt; [LSig GhcPs]
-&gt; RnM (LHsBinds GhcRn, [LSig GhcRn], Uses)
</span><a href="GHC.Rename.Bind.html#rnMethodBinds"><span class="hs-identifier hs-var">rnMethodBinds</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var hs-var">is_cls_nm</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621681168867"><span class="hs-identifier hs-var">inst</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-317"></span><span>                                                          </span><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168861"><span class="hs-identifier hs-var">tyvars</span></a></span><span> </span><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168863"><span class="hs-identifier hs-var">binds</span></a></span><span> </span><span class="annot"><span class="annottext">[LSig GhcPs]
</span><a href="#local-6989586621681168859"><span class="hs-identifier hs-var">sigs</span></a></span><span>
</span><span id="line-318"></span><span>              </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168849"><span class="annot"><span class="annottext">binds' :: InstBindings GhcRn
</span><a href="#local-6989586621681168849"><span class="hs-identifier hs-var hs-var">binds'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstBindings :: forall a.
[Name]
-&gt; LHsBinds a -&gt; [LSig a] -&gt; [Extension] -&gt; Bool -&gt; InstBindings a
</span><a href="GHC.Tc.Utils.Env.html#InstBindings"><span class="hs-identifier hs-type">InstBindings</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ib_binds :: LHsBinds GhcRn
</span><a href="GHC.Tc.Utils.Env.html#ib_binds"><span class="hs-identifier hs-var">ib_binds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">LHsBinds GhcRn
</span><a href="#local-6989586621681168854"><span class="hs-identifier hs-var">rn_binds</span></a></span><span>
</span><span id="line-319"></span><span>                                          </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_tyvars :: [Name]
</span><a href="GHC.Tc.Utils.Env.html#ib_tyvars"><span class="hs-identifier hs-var">ib_tyvars</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168861"><span class="hs-identifier hs-var">tyvars</span></a></span><span>
</span><span id="line-320"></span><span>                                          </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_pragmas :: [LSig GhcRn]
</span><a href="GHC.Tc.Utils.Env.html#ib_pragmas"><span class="hs-identifier hs-var">ib_pragmas</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[LSig GhcRn]
</span><a href="#local-6989586621681168853"><span class="hs-identifier hs-var">rn_sigs</span></a></span><span>
</span><span id="line-321"></span><span>                                          </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_extensions :: [Extension]
</span><a href="GHC.Tc.Utils.Env.html#ib_extensions"><span class="hs-identifier hs-var">ib_extensions</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Extension]
</span><a href="#local-6989586621681168857"><span class="hs-identifier hs-var">exts</span></a></span><span>
</span><span id="line-322"></span><span>                                          </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_derived :: Bool
</span><a href="GHC.Tc.Utils.Env.html#ib_derived"><span class="hs-identifier hs-var">ib_derived</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168855"><span class="hs-identifier hs-var">sa</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-323"></span><span>              </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(InstInfo GhcRn, Uses)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (InstInfo GhcRn, Uses)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InstInfo GhcPs
</span><a href="#local-6989586621681168869"><span class="hs-identifier hs-var">inst_info</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">iBinds :: InstBindings GhcRn
</span><a href="GHC.Tc.Utils.Env.html#iBinds"><span class="hs-identifier hs-var">iBinds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstBindings GhcRn
</span><a href="#local-6989586621681168849"><span class="hs-identifier hs-var">binds'</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Uses
</span><a href="#local-6989586621681168852"><span class="hs-identifier hs-var">fvs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-324"></span><span>
</span><span id="line-325"></span><span class="hs-comment">{-
Note [Staging of tcDeriving]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here's a tricky corner case for deriving (adapted from #2721):

    class C a where
      type T a
      foo :: a -&gt; T a

    instance C Int where
      type T Int = Int
      foo = id

    newtype N = N Int deriving C

This will produce an instance something like this:

    instance C N where
      type T N = T Int
      foo = coerce (foo :: Int -&gt; T Int) :: N -&gt; T N

We must be careful in order to typecheck this code. When determining the
context for the instance (in simplifyInstanceContexts), we need to determine
that T N and T Int have the same representation, but to do that, the T N
instance must be in the local family instance environment. Otherwise, GHC
would be unable to conclude that T Int is representationally equivalent to
T Int, and simplifyInstanceContexts would get stuck.

Previously, tcDeriving would defer adding any derived type family instances to
the instance environment until the very end, which meant that
simplifyInstanceContexts would get called without all the type family instances
it needed in the environment in order to properly simplify instance like
the C N instance above.

To avoid this scenario, we carefully structure the order of events in
tcDeriving. We first call genInst on the standalone derived instance specs and
the instance specs obtained from deriving clauses. Note that the return type of
genInst is a triple:

    TcM (ThetaType -&gt; TcM (InstInfo RdrName), BagDerivStuff, Maybe Name)

The type family instances are in the BagDerivStuff. The first field of the
triple is a suspended computation which, given an instance context, produces
the rest of the instance. The fact that it is suspended is important, because
right now, we don't have ThetaTypes for the instances that use deriving clauses
(only the standalone-derived ones).

Now we can collect the type family instances and extend the local instance
environment. At this point, it is safe to run simplifyInstanceContexts on the
deriving-clause instance specs, which gives us the ThetaTypes for the
deriving-clause instances. Now we can feed all the ThetaTypes to the
suspended computations and obtain our InstInfos, at which point
tcDeriving is done.

An alternative design would be to split up genInst so that the
family instances are generated separately from the InstInfos. But this would
require carving up a lot of the GHC deriving internals to accommodate the
change. On the other hand, we can keep all of the InstInfo and type family
instance logic together in genInst simply by converting genInst to
continuation-returning style, so we opt for that route.

Note [Why we don't pass rep_tc into deriveTyData]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Down in the bowels of mk_deriv_inst_tys_maybe, we need to convert the fam_tc
back into the rep_tc by means of a lookup. And yet we have the rep_tc right
here! Why look it up again? Answer: it's just easier this way.
We drop some number of arguments from the end of the datatype definition
in deriveTyData. The arguments are dropped from the fam_tc.
This action may drop a *different* number of arguments
passed to the rep_tc, depending on how many free variables, etc., the
dropped patterns have.

Also, this technique carries over the kind substitution from deriveTyData
nicely.

Note [Avoid RebindableSyntax when deriving]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The RebindableSyntax extension interacts awkwardly with the derivation of
any stock class whose methods require the use of string literals. The Show
class is a simple example (see #12688):

  {-# LANGUAGE RebindableSyntax, OverloadedStrings #-}
  newtype Text = Text String
  fromString :: String -&gt; Text
  fromString = Text

  data Foo = Foo deriving Show

This will generate code to the effect of:

  instance Show Foo where
    showsPrec _ Foo = showString &quot;Foo&quot;

But because RebindableSyntax and OverloadedStrings are enabled, the &quot;Foo&quot;
string literal is now of type Text, not String, which showString doesn't
accept! This causes the generated Show instance to fail to typecheck.

To avoid this kind of scenario, we simply turn off RebindableSyntax entirely
in derived code.

************************************************************************
*                                                                      *
                From HsSyn to DerivSpec
*                                                                      *
************************************************************************

@makeDerivSpecs@ fishes around to find the info about needed derived instances.
-}</span><span>
</span><span id="line-433"></span><span>
</span><span id="line-434"></span><span class="annot"><a href="GHC.Tc.Deriv.html#makeDerivSpecs"><span class="hs-identifier hs-type">makeDerivSpecs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.html#DerivInfo"><span class="hs-identifier hs-type">DerivInfo</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-435"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Decls.html#LDerivDecl"><span class="hs-identifier hs-type">LDerivDecl</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-436"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-437"></span><span id="makeDerivSpecs"><span class="annot"><span class="annottext">makeDerivSpecs :: [DerivInfo] -&gt; [LDerivDecl GhcRn] -&gt; TcM [EarlyDerivSpec]
</span><a href="GHC.Tc.Deriv.html#makeDerivSpecs"><span class="hs-identifier hs-var hs-var">makeDerivSpecs</span></a></span></span><span> </span><span id="local-6989586621681168848"><span class="annot"><span class="annottext">[DerivInfo]
</span><a href="#local-6989586621681168848"><span class="hs-identifier hs-var">deriv_infos</span></a></span></span><span> </span><span id="local-6989586621681168847"><span class="annot"><span class="annottext">[LDerivDecl GhcRn]
</span><a href="#local-6989586621681168847"><span class="hs-identifier hs-var">deriv_decls</span></a></span></span><span>
</span><span id="line-438"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681168846"><span class="annot"><span class="annottext">[[EarlyDerivSpec]]
</span><a href="#local-6989586621681168846"><span class="hs-identifier hs-var">eqns1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TcM [EarlyDerivSpec]]
-&gt; IOEnv (Env TcGblEnv TcLclEnv) [[EarlyDerivSpec]]
forall (t :: * -&gt; *) (f :: * -&gt; *) a.
(Traversable t, Applicative f) =&gt;
t (f a) -&gt; f (t a)
</span><a href="../../base/src/Data.Traversable.html#sequenceA"><span class="hs-identifier hs-var">sequenceA</span></a></span><span>
</span><span id="line-439"></span><span>                     </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">TyCon
-&gt; [(Name, TyVar)]
-&gt; Maybe (LDerivStrategy GhcRn)
-&gt; [LHsSigType GhcRn]
-&gt; SDoc
-&gt; TcM [EarlyDerivSpec]
</span><a href="GHC.Tc.Deriv.html#deriveClause"><span class="hs-identifier hs-var">deriveClause</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168843"><span class="hs-identifier hs-var">rep_tc</span></a></span><span> </span><span class="annot"><span class="annottext">[(Name, TyVar)]
</span><a href="#local-6989586621681168842"><span class="hs-identifier hs-var">scoped_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
</span><a href="#local-6989586621681168841"><span class="hs-identifier hs-var">dcs</span></a></span><span> </span><span class="annot"><span class="annottext">[LHsSigType GhcRn]
</span><a href="#local-6989586621681168840"><span class="hs-identifier hs-var">preds</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168839"><span class="hs-identifier hs-var">err_ctxt</span></a></span><span>
</span><span id="line-440"></span><span>                     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#DerivInfo"><span class="hs-identifier hs-type">DerivInfo</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">di_rep_tc :: DerivInfo -&gt; TyCon
</span><a href="GHC.Tc.Deriv.html#di_rep_tc"><span class="hs-identifier hs-var">di_rep_tc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168843"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168843"><span class="hs-identifier hs-var">rep_tc</span></a></span></span><span>
</span><span id="line-441"></span><span>                                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">di_scoped_tvs :: DerivInfo -&gt; [(Name, TyVar)]
</span><a href="GHC.Tc.Deriv.html#di_scoped_tvs"><span class="hs-identifier hs-var">di_scoped_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168842"><span class="annot"><span class="annottext">[(Name, TyVar)]
</span><a href="#local-6989586621681168842"><span class="hs-identifier hs-var">scoped_tvs</span></a></span></span><span>
</span><span id="line-442"></span><span>                                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">di_clauses :: DerivInfo -&gt; [LHsDerivingClause GhcRn]
</span><a href="GHC.Tc.Deriv.html#di_clauses"><span class="hs-identifier hs-var">di_clauses</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168838"><span class="annot"><span class="annottext">[LHsDerivingClause GhcRn]
</span><a href="#local-6989586621681168838"><span class="hs-identifier hs-var">clauses</span></a></span></span><span>
</span><span id="line-443"></span><span>                                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">di_ctxt :: DerivInfo -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#di_ctxt"><span class="hs-identifier hs-var">di_ctxt</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168839"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168839"><span class="hs-identifier hs-var">err_ctxt</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[DerivInfo]
</span><a href="#local-6989586621681168848"><span class="hs-identifier hs-var">deriv_infos</span></a></span><span>
</span><span id="line-444"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#HsDerivingClause"><span class="hs-identifier hs-type">HsDerivingClause</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">deriv_clause_strategy :: forall pass. HsDerivingClause pass -&gt; Maybe (LDerivStrategy pass)
</span><a href="GHC.Hs.Decls.html#deriv_clause_strategy"><span class="hs-identifier hs-var">deriv_clause_strategy</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168841"><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
</span><a href="#local-6989586621681168841"><span class="hs-identifier hs-var">dcs</span></a></span></span><span>
</span><span id="line-445"></span><span>                                             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">deriv_clause_tys :: forall pass. HsDerivingClause pass -&gt; Located [LHsSigType pass]
</span><a href="GHC.Hs.Decls.html#deriv_clause_tys"><span class="hs-identifier hs-var">deriv_clause_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621681168840"><span class="annot"><span class="annottext">[LHsSigType GhcRn]
</span><a href="#local-6989586621681168840"><span class="hs-identifier hs-var">preds</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-446"></span><span>                         </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[LHsDerivingClause GhcRn]
</span><a href="#local-6989586621681168838"><span class="hs-identifier hs-var">clauses</span></a></span><span>
</span><span id="line-447"></span><span>                     </span><span class="hs-special">]</span><span>
</span><span id="line-448"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168833"><span class="annot"><span class="annottext">[Maybe EarlyDerivSpec]
</span><a href="#local-6989586621681168833"><span class="hs-identifier hs-var">eqns2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(LDerivDecl GhcRn
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec))
-&gt; [LDerivDecl GhcRn]
-&gt; IOEnv (Env TcGblEnv TcLclEnv) [Maybe EarlyDerivSpec]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall r. TcRn r -&gt; TcRn r -&gt; TcRn r
</span><a href="GHC.Tc.Utils.Monad.html#recoverM"><span class="hs-identifier hs-var">recoverM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe EarlyDerivSpec
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe EarlyDerivSpec
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec))
-&gt; (LDerivDecl GhcRn
    -&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec))
-&gt; LDerivDecl GhcRn
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">LDerivDecl GhcRn
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
</span><a href="GHC.Tc.Deriv.html#deriveStandalone"><span class="hs-identifier hs-var">deriveStandalone</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[LDerivDecl GhcRn]
</span><a href="#local-6989586621681168847"><span class="hs-identifier hs-var">deriv_decls</span></a></span><span>
</span><span id="line-449"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">[EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">([EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec])
-&gt; [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[[EarlyDerivSpec]] -&gt; [EarlyDerivSpec]
forall (t :: * -&gt; *) a. Foldable t =&gt; t [a] -&gt; [a]
</span><a href="../../base/src/Data.Foldable.html#concat"><span class="hs-identifier hs-var">concat</span></a></span><span> </span><span class="annot"><span class="annottext">[[EarlyDerivSpec]]
</span><a href="#local-6989586621681168846"><span class="hs-identifier hs-var">eqns1</span></a></span><span> </span><span class="annot"><span class="annottext">[EarlyDerivSpec] -&gt; [EarlyDerivSpec] -&gt; [EarlyDerivSpec]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe EarlyDerivSpec] -&gt; [EarlyDerivSpec]
forall a. [Maybe a] -&gt; [a]
</span><a href="../../base/src/Data.Maybe.html#catMaybes"><span class="hs-identifier hs-var">catMaybes</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe EarlyDerivSpec]
</span><a href="#local-6989586621681168833"><span class="hs-identifier hs-var">eqns2</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-450"></span><span>
</span><span id="line-451"></span><span class="hs-comment">------------------------------------------------------------------</span><span>
</span><span id="line-452"></span><span class="hs-comment">-- | Process the derived classes in a single @deriving@ clause.</span><span>
</span><span id="line-453"></span><span class="annot"><a href="GHC.Tc.Deriv.html#deriveClause"><span class="hs-identifier hs-type">deriveClause</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span>
</span><span id="line-454"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TcTyVar"><span class="hs-identifier hs-type">TcTyVar</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- Scoped type variables taken from tcTyConScopedTyVars</span><span>
</span><span id="line-455"></span><span>                                   </span><span class="hs-comment">-- See Note [Scoped tyvars in a TcTyCon] in &quot;GHC.Core.TyCon&quot;</span><span>
</span><span id="line-456"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#LDerivStrategy"><span class="hs-identifier hs-type">LDerivStrategy</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-457"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Type.html#LHsSigType"><span class="hs-identifier hs-type">LHsSigType</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-458"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-459"></span><span id="deriveClause"><span class="annot"><span class="annottext">deriveClause :: TyCon
-&gt; [(Name, TyVar)]
-&gt; Maybe (LDerivStrategy GhcRn)
-&gt; [LHsSigType GhcRn]
-&gt; SDoc
-&gt; TcM [EarlyDerivSpec]
</span><a href="GHC.Tc.Deriv.html#deriveClause"><span class="hs-identifier hs-var hs-var">deriveClause</span></a></span></span><span> </span><span id="local-6989586621681168828"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168828"><span class="hs-identifier hs-var">rep_tc</span></a></span></span><span> </span><span id="local-6989586621681168827"><span class="annot"><span class="annottext">[(Name, TyVar)]
</span><a href="#local-6989586621681168827"><span class="hs-identifier hs-var">scoped_tvs</span></a></span></span><span> </span><span id="local-6989586621681168826"><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
</span><a href="#local-6989586621681168826"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span></span><span> </span><span id="local-6989586621681168825"><span class="annot"><span class="annottext">[LHsSigType GhcRn]
</span><a href="#local-6989586621681168825"><span class="hs-identifier hs-var">deriv_preds</span></a></span></span><span> </span><span id="local-6989586621681168824"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168824"><span class="hs-identifier hs-var">err_ctxt</span></a></span></span><span>
</span><span id="line-460"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; TcM [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec]
forall a. SDoc -&gt; TcM a -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#addErrCtxt"><span class="hs-identifier hs-var">addErrCtxt</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168824"><span class="hs-identifier hs-var">err_ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec])
-&gt; TcM [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-461"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;deriveClause&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcRn ()) -&gt; SDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span>
</span><span id="line-462"></span><span>        </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;tvs&quot;</span></span><span>             </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168822"><span class="hs-identifier hs-var">tvs</span></a></span><span>
</span><span id="line-463"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;scoped_tvs&quot;</span></span><span>      </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[(Name, TyVar)] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[(Name, TyVar)]
</span><a href="#local-6989586621681168827"><span class="hs-identifier hs-var">scoped_tvs</span></a></span><span>
</span><span id="line-464"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;tc&quot;</span></span><span>              </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168821"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-465"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;tys&quot;</span></span><span>             </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168820"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-466"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;mb_lderiv_strat&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn) -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
</span><a href="#local-6989586621681168826"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-467"></span><span>      </span><span class="annot"><span class="annottext">[(Name, TyVar)] -&gt; TcM [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec]
forall r. [(Name, TyVar)] -&gt; TcM r -&gt; TcM r
</span><a href="GHC.Tc.Utils.Env.html#tcExtendNameTyVarEnv"><span class="hs-identifier hs-var">tcExtendNameTyVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">[(Name, TyVar)]
</span><a href="#local-6989586621681168827"><span class="hs-identifier hs-var">scoped_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec])
-&gt; TcM [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-468"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621681168818"><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcTc)
</span><a href="#local-6989586621681168818"><span class="hs-identifier hs-var">mb_lderiv_strat'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168817"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168817"><span class="hs-identifier hs-var">via_tvs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
-&gt; TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
</span><a href="GHC.Tc.Gen.HsType.html#tcDerivStrategy"><span class="hs-identifier hs-var">tcDerivStrategy</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
</span><a href="#local-6989586621681168826"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span><span>
</span><span id="line-469"></span><span>        </span><span class="annot"><span class="annottext">[TyVar] -&gt; TcM [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec]
forall r. [TyVar] -&gt; TcM r -&gt; TcM r
</span><a href="GHC.Tc.Utils.Env.html#tcExtendTyVarEnv"><span class="hs-identifier hs-var">tcExtendTyVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168817"><span class="hs-identifier hs-var">via_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec])
-&gt; TcM [EarlyDerivSpec] -&gt; TcM [EarlyDerivSpec]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-470"></span><span>        </span><span class="hs-comment">-- Moreover, when using DerivingVia one can bind type variables in</span><span>
</span><span id="line-471"></span><span>        </span><span class="hs-comment">-- the `via` type as well, so these type variables must also be</span><span>
</span><span id="line-472"></span><span>        </span><span class="hs-comment">-- brought into scope.</span><span>
</span><span id="line-473"></span><span>          </span><span class="annot"><span class="annottext">(LHsSigType GhcRn
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec))
-&gt; [LHsSigType GhcRn] -&gt; TcM [EarlyDerivSpec]
forall (m :: * -&gt; *) a b.
Applicative m =&gt;
(a -&gt; m (Maybe b)) -&gt; [a] -&gt; m [b]
</span><a href="GHC.Utils.Monad.html#mapMaybeM"><span class="hs-identifier hs-var">mapMaybeM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon
-&gt; [PredType]
-&gt; Maybe (LDerivStrategy GhcTc)
-&gt; [TyVar]
-&gt; LHsSigType GhcRn
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
</span><a href="GHC.Tc.Deriv.html#derivePred"><span class="hs-identifier hs-var">derivePred</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168821"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168820"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcTc)
</span><a href="#local-6989586621681168818"><span class="hs-identifier hs-var">mb_lderiv_strat'</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168817"><span class="hs-identifier hs-var">via_tvs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[LHsSigType GhcRn]
</span><a href="#local-6989586621681168825"><span class="hs-identifier hs-var">deriv_preds</span></a></span><span>
</span><span id="line-474"></span><span>          </span><span class="hs-comment">-- After typechecking the `via` type once, we then typecheck all</span><span>
</span><span id="line-475"></span><span>          </span><span class="hs-comment">-- of the classes associated with that `via` type in the</span><span>
</span><span id="line-476"></span><span>          </span><span class="hs-comment">-- `deriving` clause.</span><span>
</span><span id="line-477"></span><span>          </span><span class="hs-comment">-- See also Note [Don't typecheck too much in DerivingVia].</span><span>
</span><span id="line-478"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-479"></span><span>    </span><span id="local-6989586621681168822"><span class="annot"><span class="annottext">tvs :: [TyVar]
</span><a href="#local-6989586621681168822"><span class="hs-identifier hs-var hs-var">tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TyVar]
</span><a href="GHC.Core.TyCon.html#tyConTyVars"><span class="hs-identifier hs-var hs-var">tyConTyVars</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168828"><span class="hs-identifier hs-var">rep_tc</span></a></span><span>
</span><span id="line-480"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621681168821"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168821"><span class="hs-identifier hs-var">tc</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168820"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168820"><span class="hs-identifier hs-var">tys</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Maybe (TyCon, [PredType], CoAxiom Unbranched)
</span><a href="GHC.Core.TyCon.html#tyConFamInstSig_maybe"><span class="hs-identifier hs-var">tyConFamInstSig_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168828"><span class="hs-identifier hs-var">rep_tc</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-481"></span><span>                        </span><span class="hs-comment">-- data family:</span><span>
</span><span id="line-482"></span><span>                  </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168810"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168810"><span class="hs-identifier hs-var">fam_tc</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168809"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168809"><span class="hs-identifier hs-var">pats</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoAxiom Unbranched
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168810"><span class="hs-identifier hs-var">fam_tc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168809"><span class="hs-identifier hs-var">pats</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-483"></span><span>      </span><span class="hs-comment">-- NB: deriveTyData wants the *user-specified*</span><span>
</span><span id="line-484"></span><span>      </span><span class="hs-comment">-- name. See Note [Why we don't pass rep_tc into deriveTyData]</span><span>
</span><span id="line-485"></span><span>
</span><span id="line-486"></span><span>                  </span><span class="annot"><span class="annottext">Maybe (TyCon, [PredType], CoAxiom Unbranched)
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168828"><span class="hs-identifier hs-var">rep_tc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; [PredType]
</span><a href="GHC.Core.TyCo.Rep.html#mkTyVarTys"><span class="hs-identifier hs-var">mkTyVarTys</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168822"><span class="hs-identifier hs-var">tvs</span></a></span><span class="hs-special">)</span><span>     </span><span class="hs-comment">-- datatype</span><span>
</span><span id="line-487"></span><span>
</span><span id="line-488"></span><span class="hs-comment">-- | Process a single predicate in a @deriving@ clause.</span><span>
</span><span id="line-489"></span><span class="hs-comment">--</span><span>
</span><span id="line-490"></span><span class="hs-comment">-- This returns a 'Maybe' because the user might try to derive 'Typeable',</span><span>
</span><span id="line-491"></span><span class="hs-comment">-- which is a no-op nowadays.</span><span>
</span><span id="line-492"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivePred"><span class="hs-identifier hs-type">derivePred</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#LDerivStrategy"><span class="hs-identifier hs-type">LDerivStrategy</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-493"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Hs.Type.html#LHsSigType"><span class="hs-identifier hs-type">LHsSigType</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-494"></span><span id="derivePred"><span class="annot"><span class="annottext">derivePred :: TyCon
-&gt; [PredType]
-&gt; Maybe (LDerivStrategy GhcTc)
-&gt; [TyVar]
-&gt; LHsSigType GhcRn
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
</span><a href="GHC.Tc.Deriv.html#derivePred"><span class="hs-identifier hs-var hs-var">derivePred</span></a></span></span><span> </span><span id="local-6989586621681168806"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168806"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681168805"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168805"><span class="hs-identifier hs-var">tys</span></a></span></span><span> </span><span id="local-6989586621681168804"><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcTc)
</span><a href="#local-6989586621681168804"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span></span><span> </span><span id="local-6989586621681168803"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168803"><span class="hs-identifier hs-var">via_tvs</span></a></span></span><span> </span><span id="local-6989586621681168802"><span class="annot"><span class="annottext">LHsSigType GhcRn
</span><a href="#local-6989586621681168802"><span class="hs-identifier hs-var">deriv_pred</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-495"></span><span>  </span><span class="hs-comment">-- We carefully set up uses of recoverM to minimize error message</span><span>
</span><span id="line-496"></span><span>  </span><span class="hs-comment">-- cascades. See Note [Recovering from failures in deriving clauses].</span><span>
</span><span id="line-497"></span><span>  </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall r. TcRn r -&gt; TcRn r -&gt; TcRn r
</span><a href="GHC.Tc.Utils.Monad.html#recoverM"><span class="hs-identifier hs-var">recoverM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe EarlyDerivSpec
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe EarlyDerivSpec
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec))
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-498"></span><span>  </span><span class="annot"><span class="annottext">SrcSpan
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall a. SrcSpan -&gt; TcRn a -&gt; TcRn a
</span><a href="GHC.Tc.Utils.Monad.html#setSrcSpan"><span class="hs-identifier hs-var">setSrcSpan</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn) -&gt; SrcSpan
forall l e. GenLocated l e -&gt; l
</span><a href="GHC.Types.SrcLoc.html#getLoc"><span class="hs-identifier hs-var">getLoc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">LHsSigType GhcRn -&gt; GenLocated SrcSpan (HsType GhcRn)
forall (p :: Pass). LHsSigType (GhcPass p) -&gt; LHsType (GhcPass p)
</span><a href="GHC.Hs.Type.html#hsSigType"><span class="hs-identifier hs-var">hsSigType</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigType GhcRn
</span><a href="#local-6989586621681168802"><span class="hs-identifier hs-var">deriv_pred</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec))
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-499"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;derivePred&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcRn ()) -&gt; SDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span>
</span><span id="line-500"></span><span>      </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;tc&quot;</span></span><span>              </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168806"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-501"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;tys&quot;</span></span><span>             </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168805"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-502"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;deriv_pred&quot;</span></span><span>      </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigType GhcRn -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigType GhcRn
</span><a href="#local-6989586621681168802"><span class="hs-identifier hs-var">deriv_pred</span></a></span><span>
</span><span id="line-503"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;mb_lderiv_strat&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcTc) -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcTc)
</span><a href="#local-6989586621681168804"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span><span>
</span><span id="line-504"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;via_tvs&quot;</span></span><span>         </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168803"><span class="hs-identifier hs-var">via_tvs</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-505"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621681168798"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168798"><span class="hs-identifier hs-var">cls_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168797"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168797"><span class="hs-identifier hs-var">cls</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168796"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168796"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168795"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168795"><span class="hs-identifier hs-var">cls_arg_kinds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">LHsSigType GhcRn -&gt; TcM ([TyVar], Class, [PredType], [PredType])
</span><a href="GHC.Tc.Gen.HsType.html#tcHsDeriv"><span class="hs-identifier hs-var">tcHsDeriv</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigType GhcRn
</span><a href="#local-6989586621681168802"><span class="hs-identifier hs-var">deriv_pred</span></a></span><span>
</span><span id="line-506"></span><span>    </span><span class="annot"><span class="annottext">Bool -&gt; TcRn () -&gt; TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168795"><span class="hs-identifier hs-var">cls_arg_kinds</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; Arity -&gt; Bool
forall a. [a] -&gt; Arity -&gt; Bool
</span><a href="GHC.Utils.Misc.html#lengthIsNot"><span class="hs-operator hs-var">`lengthIsNot`</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; TcRn ()) -&gt; TcRn () -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-507"></span><span>      </span><span class="annot"><span class="annottext">SDoc -&gt; TcRn ()
forall a. SDoc -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#failWithTc"><span class="hs-identifier hs-var">failWithTc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">LHsSigType GhcRn -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#nonUnaryErr"><span class="hs-identifier hs-var">nonUnaryErr</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigType GhcRn
</span><a href="#local-6989586621681168802"><span class="hs-identifier hs-var">deriv_pred</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-508"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">[</span><span id="local-6989586621681168789"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168789"><span class="hs-identifier hs-var">cls_arg_kind</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168795"><span class="hs-identifier hs-var">cls_arg_kinds</span></a></span><span>
</span><span id="line-509"></span><span>        </span><span id="local-6989586621681168788"><span class="annot"><span class="annottext">mb_deriv_strat :: Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168788"><span class="hs-identifier hs-var hs-var">mb_deriv_strat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(LDerivStrategy GhcTc -&gt; DerivStrategy GhcTc)
-&gt; Maybe (LDerivStrategy GhcTc) -&gt; Maybe (DerivStrategy GhcTc)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">LDerivStrategy GhcTc -&gt; DerivStrategy GhcTc
forall l e. GenLocated l e -&gt; e
</span><a href="GHC.Types.SrcLoc.html#unLoc"><span class="hs-identifier hs-var">unLoc</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcTc)
</span><a href="#local-6989586621681168804"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span><span>
</span><span id="line-510"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; Name
</span><a href="GHC.Core.Class.html#className"><span class="hs-identifier hs-var hs-var">className</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168797"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">Name -&gt; Name -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="GHC.Builtin.Names.html#typeableClassName"><span class="hs-identifier hs-var">typeableClassName</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-511"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TcRn ()
</span><a href="GHC.Tc.Deriv.html#warnUselessTypeable"><span class="hs-identifier hs-var">warnUselessTypeable</span></a></span><span>
</span><span id="line-512"></span><span>            </span><span class="annot"><span class="annottext">Maybe EarlyDerivSpec
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe EarlyDerivSpec
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-513"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168783"><span class="annot"><span class="annottext">deriv_tvs :: [TyVar]
</span><a href="#local-6989586621681168783"><span class="hs-identifier hs-var hs-var">deriv_tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168803"><span class="hs-identifier hs-var">via_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; [TyVar] -&gt; [TyVar]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168798"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="hs-keyword">in</span><span>
</span><span id="line-514"></span><span>         </span><span class="annot"><span class="annottext">EarlyDerivSpec -&gt; Maybe EarlyDerivSpec
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">(EarlyDerivSpec -&gt; Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) EarlyDerivSpec
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; [TyVar]
-&gt; Class
-&gt; [PredType]
-&gt; PredType
-&gt; IOEnv (Env TcGblEnv TcLclEnv) EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#deriveTyData"><span class="hs-identifier hs-var">deriveTyData</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168806"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168805"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168788"><span class="hs-identifier hs-var">mb_deriv_strat</span></a></span><span>
</span><span id="line-515"></span><span>                               </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168783"><span class="hs-identifier hs-var">deriv_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168797"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168796"><span class="hs-identifier hs-var">cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168789"><span class="hs-identifier hs-var">cls_arg_kind</span></a></span><span>
</span><span id="line-516"></span><span>
</span><span id="line-517"></span><span class="hs-comment">{-
Note [Don't typecheck too much in DerivingVia]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider the following example:

  data D = ...
    deriving (A1 t, ..., A20 t) via T t

GHC used to be engineered such that it would typecheck the `deriving`
clause like so:

1. Take the first class in the clause (`A1`).
2. Typecheck the `via` type (`T t`) and bring its bound type variables
   into scope (`t`).
3. Typecheck the class (`A1`).
4. Move on to the next class (`A2`) and repeat the process until all
   classes have been typechecked.

This algorithm gets the job done most of the time, but it has two notable
flaws. One flaw is that it is wasteful: it requires that `T t` be typechecked
20 different times, once for each class in the `deriving` clause. This is
unnecessary because we only need to typecheck `T t` once in order to get
access to its bound type variable.

The other issue with this algorithm arises when there are no classes in the
`deriving` clause, like in the following example:

  data D2 = ...
    deriving () via Maybe Maybe

Because there are no classes, the algorithm above will simply do nothing.
As a consequence, GHC will completely miss the fact that `Maybe Maybe`
is ill-kinded nonsense (#16923).

To address both of these problems, GHC now uses this algorithm instead:

1. Typecheck the `via` type and bring its bound type variables into scope.
2. Take the first class in the `deriving` clause.
3. Typecheck the class.
4. Move on to the next class and repeat the process until all classes have been
   typechecked.

This algorithm ensures that the `via` type is always typechecked, even if there
are no classes in the `deriving` clause. Moreover, it typecheck the `via` type
/exactly/ once and no more, even if there are multiple classes in the clause.

Note [Recovering from failures in deriving clauses]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider what happens if you run this program (from #10684) without
DeriveGeneric enabled:

    data A = A deriving (Show, Generic)
    data B = B A deriving (Show)

Naturally, you'd expect GHC to give an error to the effect of:

    Can't make a derived instance of `Generic A':
      You need -XDeriveGeneric to derive an instance for this class

And *only* that error, since the other two derived Show instances appear to be
independent of this derived Generic instance. Yet GHC also used to give this
additional error on the program above:

    No instance for (Show A)
      arising from the 'deriving' clause of a data type declaration
    When deriving the instance for (Show B)

This was happening because when GHC encountered any error within a single
data type's set of deriving clauses, it would call recoverM and move on
to the next data type's deriving clauses. One unfortunate consequence of
this design is that if A's derived Generic instance failed, its derived
Show instance would be skipped entirely, leading to the &quot;No instance for
(Show A)&quot; error cascade.

The solution to this problem is to push through uses of recoverM to the
level of the individual derived classes in a particular data type's set of
deriving clauses. That is, if you have:

    newtype C = C D
      deriving (E, F, G)

Then instead of processing instances E through M under the scope of a single
recoverM, as in the following pseudocode:

  recoverM (pure Nothing) $ mapM derivePred [E, F, G]

We instead use recoverM in each iteration of the loop:

  mapM (recoverM (pure Nothing) . derivePred) [E, F, G]

And then process each class individually, under its own recoverM scope. That
way, failure to derive one class doesn't cancel out other classes in the
same set of clause-derived classes.
-}</span><span>
</span><span id="line-611"></span><span>
</span><span id="line-612"></span><span class="hs-comment">------------------------------------------------------------------</span><span>
</span><span id="line-613"></span><span class="annot"><a href="GHC.Tc.Deriv.html#deriveStandalone"><span class="hs-identifier hs-type">deriveStandalone</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Hs.Decls.html#LDerivDecl"><span class="hs-identifier hs-type">LDerivDecl</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-614"></span><span class="hs-comment">-- Process a single standalone deriving declaration</span><span>
</span><span id="line-615"></span><span class="hs-comment">--  e.g.   deriving instance Show a =&gt; Show (T a)</span><span>
</span><span id="line-616"></span><span class="hs-comment">-- Rather like tcLocalInstDecl</span><span>
</span><span id="line-617"></span><span class="hs-comment">--</span><span>
</span><span id="line-618"></span><span class="hs-comment">-- This returns a Maybe because the user might try to derive Typeable, which is</span><span>
</span><span id="line-619"></span><span class="hs-comment">-- a no-op nowadays.</span><span>
</span><span id="line-620"></span><span id="deriveStandalone"><span class="annot"><span class="annottext">deriveStandalone :: LDerivDecl GhcRn
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
</span><a href="GHC.Tc.Deriv.html#deriveStandalone"><span class="hs-identifier hs-var hs-var">deriveStandalone</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span id="local-6989586621681168780"><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168780"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#DerivDecl"><span class="hs-identifier hs-type">DerivDecl</span></a></span><span> </span><span class="annot"><span class="annottext">XCDerivDecl GhcRn
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621681168778"><span class="annot"><span class="annottext">LHsSigWcType GhcRn
</span><a href="#local-6989586621681168778"><span class="hs-identifier hs-var">deriv_ty</span></a></span></span><span> </span><span id="local-6989586621681168777"><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
</span><a href="#local-6989586621681168777"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span></span><span> </span><span id="local-6989586621681168776"><span class="annot"><span class="annottext">Maybe (Located OverlapMode)
</span><a href="#local-6989586621681168776"><span class="hs-identifier hs-var">overlap_mode</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-621"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SrcSpan
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall a. SrcSpan -&gt; TcRn a -&gt; TcRn a
</span><a href="GHC.Tc.Utils.Monad.html#setSrcSpan"><span class="hs-identifier hs-var">setSrcSpan</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168780"><span class="hs-identifier hs-var">loc</span></a></span><span>                   </span><span class="annot"><span class="annottext">(IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec))
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-622"></span><span>    </span><span class="annot"><span class="annottext">SDoc
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall a. SDoc -&gt; TcM a -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#addErrCtxt"><span class="hs-identifier hs-var">addErrCtxt</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">LHsSigWcType GhcRn -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#standaloneCtxt"><span class="hs-identifier hs-var">standaloneCtxt</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigWcType GhcRn
</span><a href="#local-6989586621681168778"><span class="hs-identifier hs-var">deriv_ty</span></a></span><span class="hs-special">)</span><span>  </span><span class="annot"><span class="annottext">(IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec))
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-623"></span><span>    </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Standalone deriving decl for&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">LHsSigWcType GhcRn -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigWcType GhcRn
</span><a href="#local-6989586621681168778"><span class="hs-identifier hs-var">deriv_ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-624"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168774"><span class="annot"><span class="annottext">ctxt :: UserTypeCtxt
</span><a href="#local-6989586621681168774"><span class="hs-identifier hs-var hs-var">ctxt</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; UserTypeCtxt
</span><a href="GHC.Tc.Types.Origin.html#InstDeclCtxt"><span class="hs-identifier hs-var">GHC.Tc.Types.Origin.InstDeclCtxt</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-625"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Deriving strategy (standalone deriving)&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcRn ()) -&gt; SDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-626"></span><span>           </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn) -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
</span><a href="#local-6989586621681168777"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">LHsSigWcType GhcRn -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigWcType GhcRn
</span><a href="#local-6989586621681168778"><span class="hs-identifier hs-var">deriv_ty</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-627"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168772"><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcTc)
</span><a href="#local-6989586621681168772"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168771"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168771"><span class="hs-identifier hs-var">via_tvs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
-&gt; TcM (Maybe (LDerivStrategy GhcTc), [TyVar])
</span><a href="GHC.Tc.Gen.HsType.html#tcDerivStrategy"><span class="hs-identifier hs-var">tcDerivStrategy</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcRn)
</span><a href="#local-6989586621681168777"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span><span>
</span><span id="line-628"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168770"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168770"><span class="hs-identifier hs-var">cls_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168769"><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168769"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168768"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168768"><span class="hs-identifier hs-var">cls</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168767"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168767"><span class="hs-identifier hs-var">inst_tys</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-629"></span><span>           </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TyVar]
-&gt; TcM ([TyVar], DerivContext, Class, [PredType])
-&gt; TcM ([TyVar], DerivContext, Class, [PredType])
forall r. [TyVar] -&gt; TcM r -&gt; TcM r
</span><a href="GHC.Tc.Utils.Env.html#tcExtendTyVarEnv"><span class="hs-identifier hs-var">tcExtendTyVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168771"><span class="hs-identifier hs-var">via_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM ([TyVar], DerivContext, Class, [PredType])
 -&gt; TcM ([TyVar], DerivContext, Class, [PredType]))
-&gt; TcM ([TyVar], DerivContext, Class, [PredType])
-&gt; TcM ([TyVar], DerivContext, Class, [PredType])
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-630"></span><span>              </span><span class="annot"><span class="annottext">UserTypeCtxt
-&gt; LHsSigWcType GhcRn
-&gt; TcM ([TyVar], DerivContext, Class, [PredType])
</span><a href="GHC.Tc.Deriv.html#tcStandaloneDerivInstType"><span class="hs-identifier hs-var">tcStandaloneDerivInstType</span></a></span><span> </span><span class="annot"><span class="annottext">UserTypeCtxt
</span><a href="#local-6989586621681168774"><span class="hs-identifier hs-var">ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigWcType GhcRn
</span><a href="#local-6989586621681168778"><span class="hs-identifier hs-var">deriv_ty</span></a></span><span>
</span><span id="line-631"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168765"><span class="annot"><span class="annottext">mb_deriv_strat :: Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168765"><span class="hs-identifier hs-var hs-var">mb_deriv_strat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(LDerivStrategy GhcTc -&gt; DerivStrategy GhcTc)
-&gt; Maybe (LDerivStrategy GhcTc) -&gt; Maybe (DerivStrategy GhcTc)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">LDerivStrategy GhcTc -&gt; DerivStrategy GhcTc
forall l e. GenLocated l e -&gt; e
</span><a href="GHC.Types.SrcLoc.html#unLoc"><span class="hs-identifier hs-var">unLoc</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (LDerivStrategy GhcTc)
</span><a href="#local-6989586621681168772"><span class="hs-identifier hs-var">mb_lderiv_strat</span></a></span><span>
</span><span id="line-632"></span><span>             </span><span id="local-6989586621681168764"><span class="annot"><span class="annottext">tvs :: [TyVar]
</span><a href="#local-6989586621681168764"><span class="hs-identifier hs-var hs-var">tvs</span></a></span></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168771"><span class="hs-identifier hs-var">via_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; [TyVar] -&gt; [TyVar]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168770"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span>
</span><span id="line-633"></span><span>         </span><span class="hs-comment">-- See Note [Unify kinds in deriving]</span><span>
</span><span id="line-634"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168763"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168763"><span class="hs-identifier hs-var">tvs'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168762"><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168762"><span class="hs-identifier hs-var">deriv_ctxt'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168761"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168761"><span class="hs-identifier hs-var">inst_tys'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168760"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168760"><span class="hs-identifier hs-var">mb_deriv_strat'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-635"></span><span>           </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168765"><span class="hs-identifier hs-var">mb_deriv_strat</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-636"></span><span>             </span><span class="hs-comment">-- Perform an additional unification with the kind of the `via`</span><span>
</span><span id="line-637"></span><span>             </span><span class="hs-comment">-- type and the result of the previous kind unification.</span><span>
</span><span id="line-638"></span><span>             </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#ViaStrategy"><span class="hs-identifier hs-type">ViaStrategy</span></a></span><span> </span><span id="local-6989586621681168758"><span class="annot"><span class="annottext">XViaStrategy GhcTc
</span><a href="#local-6989586621681168758"><span class="hs-identifier hs-var">via_ty</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-639"></span><span>                  </span><span class="hs-comment">-- This unification must be performed on the last element of</span><span>
</span><span id="line-640"></span><span>                  </span><span class="hs-comment">-- inst_tys, but we have not yet checked for this property.</span><span>
</span><span id="line-641"></span><span>                  </span><span class="hs-comment">-- (This is done later in expectNonNullaryClsArgs). For now,</span><span>
</span><span id="line-642"></span><span>                  </span><span class="hs-comment">-- simply do nothing if inst_tys is empty, since</span><span>
</span><span id="line-643"></span><span>                  </span><span class="hs-comment">-- expectNonNullaryClsArgs will error later if this</span><span>
</span><span id="line-644"></span><span>                  </span><span class="hs-comment">-- is the case.</span><span>
</span><span id="line-645"></span><span>               </span><span class="hs-glyph">|</span><span>  </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681168757"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168757"><span class="hs-identifier hs-var">inst_ty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; Maybe PredType
forall a. [a] -&gt; Maybe a
</span><a href="GHC.Utils.Misc.html#lastMaybe"><span class="hs-identifier hs-var">lastMaybe</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168767"><span class="hs-identifier hs-var">inst_tys</span></a></span><span>
</span><span id="line-646"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-647"></span><span>               </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168755"><span class="annot"><span class="annottext">via_kind :: PredType
</span><a href="#local-6989586621681168755"><span class="hs-identifier hs-var hs-var">via_kind</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; PredType -&gt; PredType
PredType -&gt; PredType
</span><a href="GHC.Core.Type.html#tcTypeKind"><span class="hs-identifier hs-var">tcTypeKind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
XViaStrategy GhcTc
</span><a href="#local-6989586621681168758"><span class="hs-identifier hs-var">via_ty</span></a></span><span>
</span><span id="line-648"></span><span>                   </span><span id="local-6989586621681168753"><span class="annot"><span class="annottext">inst_ty_kind :: PredType
</span><a href="#local-6989586621681168753"><span class="hs-identifier hs-var hs-var">inst_ty_kind</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; PredType -&gt; PredType
PredType -&gt; PredType
</span><a href="GHC.Core.Type.html#tcTypeKind"><span class="hs-identifier hs-var">tcTypeKind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168757"><span class="hs-identifier hs-var">inst_ty</span></a></span><span>
</span><span id="line-649"></span><span>                   </span><span id="local-6989586621681168752"><span class="annot"><span class="annottext">mb_match :: Maybe TCvSubst
</span><a href="#local-6989586621681168752"><span class="hs-identifier hs-var hs-var">mb_match</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PredType -&gt; PredType -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcUnifyTy"><span class="hs-identifier hs-var">tcUnifyTy</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168753"><span class="hs-identifier hs-var">inst_ty_kind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168755"><span class="hs-identifier hs-var">via_kind</span></a></span><span>
</span><span id="line-650"></span><span>
</span><span id="line-651"></span><span>               </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#checkTc"><span class="hs-identifier hs-var">checkTc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe TCvSubst -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="#local-6989586621681168752"><span class="hs-identifier hs-var">mb_match</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-652"></span><span>                       </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; PredType -&gt; PredType -&gt; PredType -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingViaKindErr"><span class="hs-identifier hs-var">derivingViaKindErr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168768"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168753"><span class="hs-identifier hs-var">inst_ty_kind</span></a></span><span>
</span><span id="line-653"></span><span>                                           </span><span class="annot"><span class="annottext">PredType
XViaStrategy GhcTc
</span><a href="#local-6989586621681168758"><span class="hs-identifier hs-var">via_ty</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168755"><span class="hs-identifier hs-var">via_kind</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-654"></span><span>
</span><span id="line-655"></span><span>               </span><span class="hs-keyword">let</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681168748"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168748"><span class="hs-identifier hs-var">kind_subst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="#local-6989586621681168752"><span class="hs-identifier hs-var">mb_match</span></a></span><span>
</span><span id="line-656"></span><span>                   </span><span id="local-6989586621681168747"><span class="annot"><span class="annottext">ki_subst_range :: VarSet
</span><a href="#local-6989586621681168747"><span class="hs-identifier hs-var hs-var">ki_subst_range</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TCvSubst -&gt; VarSet
</span><a href="GHC.Core.TyCo.Subst.html#getTCvSubstRangeFVs"><span class="hs-identifier hs-var">getTCvSubstRangeFVs</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168748"><span class="hs-identifier hs-var">kind_subst</span></a></span><span>
</span><span id="line-657"></span><span>                   </span><span class="hs-comment">-- See Note [Unification of two kind variables in deriving]</span><span>
</span><span id="line-658"></span><span>                   </span><span id="local-6989586621681168745"><span class="annot"><span class="annottext">unmapped_tkvs :: [TyVar]
</span><a href="#local-6989586621681168745"><span class="hs-identifier hs-var hs-var">unmapped_tkvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TyVar -&gt; Bool) -&gt; [TyVar] -&gt; [TyVar]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621681168744"><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621681168744"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621681168744"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; TCvSubst -&gt; Bool
</span><a href="GHC.Core.TyCo.Subst.html#notElemTCvSubst"><span class="hs-operator hs-var">`notElemTCvSubst`</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168748"><span class="hs-identifier hs-var">kind_subst</span></a></span><span>
</span><span id="line-659"></span><span>                                        </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621681168744"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#elemVarSet"><span class="hs-operator hs-var">`elemVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621681168747"><span class="hs-identifier hs-var">ki_subst_range</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-660"></span><span>                                          </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168764"><span class="hs-identifier hs-var">tvs</span></a></span><span>
</span><span id="line-661"></span><span>                   </span><span class="hs-special">(</span><span id="local-6989586621681168739"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168739"><span class="hs-identifier hs-var">subst</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; [TyVar] -&gt; (TCvSubst, [TyVar])
TCvSubst -&gt; [TyVar] -&gt; (TCvSubst, [TyVar])
</span><a href="GHC.Core.TyCo.Subst.html#substTyVarBndrs"><span class="hs-identifier hs-var">substTyVarBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168748"><span class="hs-identifier hs-var">kind_subst</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168745"><span class="hs-identifier hs-var">unmapped_tkvs</span></a></span><span>
</span><span id="line-662"></span><span>                   </span><span class="hs-special">(</span><span id="local-6989586621681168737"><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168737"><span class="hs-identifier hs-var">final_deriv_ctxt</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168736"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168736"><span class="hs-identifier hs-var">final_deriv_ctxt_tys</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-663"></span><span>                     </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168769"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-664"></span><span>                         </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#InferContext"><span class="hs-identifier hs-type">InferContext</span></a></span><span> </span><span id="local-6989586621681168734"><span class="annot"><span class="annottext">Maybe SrcSpan
</span><a href="#local-6989586621681168734"><span class="hs-identifier hs-var">wc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe SrcSpan -&gt; DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#InferContext"><span class="hs-identifier hs-var">InferContext</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe SrcSpan
</span><a href="#local-6989586621681168734"><span class="hs-identifier hs-var">wc</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-665"></span><span>                         </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#SupplyContext"><span class="hs-identifier hs-type">SupplyContext</span></a></span><span> </span><span id="local-6989586621681168732"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168732"><span class="hs-identifier hs-var">theta</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-666"></span><span>                           </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168731"><span class="annot"><span class="annottext">final_theta :: [PredType]
</span><a href="#local-6989586621681168731"><span class="hs-identifier hs-var hs-var">final_theta</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; [PredType] -&gt; [PredType]
TCvSubst -&gt; [PredType] -&gt; [PredType]
</span><a href="GHC.Core.TyCo.Subst.html#substTheta"><span class="hs-identifier hs-var">substTheta</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168739"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168732"><span class="hs-identifier hs-var">theta</span></a></span><span>
</span><span id="line-667"></span><span>                           </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[PredType] -&gt; DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#SupplyContext"><span class="hs-identifier hs-var">SupplyContext</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168731"><span class="hs-identifier hs-var">final_theta</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168731"><span class="hs-identifier hs-var">final_theta</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-668"></span><span>                   </span><span id="local-6989586621681168729"><span class="annot"><span class="annottext">final_inst_tys :: [PredType]
</span><a href="#local-6989586621681168729"><span class="hs-identifier hs-var hs-var">final_inst_tys</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; [PredType] -&gt; [PredType]
TCvSubst -&gt; [PredType] -&gt; [PredType]
</span><a href="GHC.Core.TyCo.Subst.html#substTys"><span class="hs-identifier hs-var">substTys</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168739"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168767"><span class="hs-identifier hs-var">inst_tys</span></a></span><span>
</span><span id="line-669"></span><span>                   </span><span id="local-6989586621681168727"><span class="annot"><span class="annottext">final_via_ty :: PredType
</span><a href="#local-6989586621681168727"><span class="hs-identifier hs-var hs-var">final_via_ty</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; PredType -&gt; PredType
TCvSubst -&gt; PredType -&gt; PredType
</span><a href="GHC.Core.TyCo.Subst.html#substTy"><span class="hs-identifier hs-var">substTy</span></a></span><span>  </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168739"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
XViaStrategy GhcTc
</span><a href="#local-6989586621681168758"><span class="hs-identifier hs-var">via_ty</span></a></span><span>
</span><span id="line-670"></span><span>                   </span><span class="hs-comment">-- See Note [Floating `via` type variables]</span><span>
</span><span id="line-671"></span><span>                   </span><span id="local-6989586621681168725"><span class="annot"><span class="annottext">final_tvs :: [TyVar]
</span><a href="#local-6989586621681168725"><span class="hs-identifier hs-var hs-var">final_tvs</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; [TyVar]
</span><a href="GHC.Core.TyCo.FVs.html#tyCoVarsOfTypesWellScoped"><span class="hs-identifier hs-var">tyCoVarsOfTypesWellScoped</span></a></span><span> </span><span class="annot"><span class="annottext">([PredType] -&gt; [TyVar]) -&gt; [PredType] -&gt; [TyVar]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-672"></span><span>                                      </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168736"><span class="hs-identifier hs-var">final_deriv_ctxt_tys</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; [PredType] -&gt; [PredType]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168729"><span class="hs-identifier hs-var">final_inst_tys</span></a></span><span>
</span><span id="line-673"></span><span>                                        </span><span class="annot"><span class="annottext">[PredType] -&gt; [PredType] -&gt; [PredType]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168727"><span class="hs-identifier hs-var">final_via_ty</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-674"></span><span>               </span><span class="annot"><span class="annottext">([TyVar], DerivContext, [PredType], Maybe (DerivStrategy GhcTc))
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([TyVar], DerivContext, [PredType], Maybe (DerivStrategy GhcTc))
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168725"><span class="hs-identifier hs-var">final_tvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168737"><span class="hs-identifier hs-var">final_deriv_ctxt</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168729"><span class="hs-identifier hs-var">final_inst_tys</span></a></span><span>
</span><span id="line-675"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DerivStrategy GhcTc -&gt; Maybe (DerivStrategy GhcTc)
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">XViaStrategy GhcTc -&gt; DerivStrategy GhcTc
forall pass. XViaStrategy pass -&gt; DerivStrategy pass
</span><a href="GHC.Hs.Decls.html#ViaStrategy"><span class="hs-identifier hs-var">ViaStrategy</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
XViaStrategy GhcTc
</span><a href="#local-6989586621681168727"><span class="hs-identifier hs-var">final_via_ty</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-676"></span><span>
</span><span id="line-677"></span><span>             </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">([TyVar], DerivContext, [PredType], Maybe (DerivStrategy GhcTc))
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([TyVar], DerivContext, [PredType], Maybe (DerivStrategy GhcTc))
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168764"><span class="hs-identifier hs-var">tvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168769"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168767"><span class="hs-identifier hs-var">inst_tys</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168765"><span class="hs-identifier hs-var">mb_deriv_strat</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-678"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Standalone deriving;&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcRn ()) -&gt; SDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span>
</span><span id="line-679"></span><span>              </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;tvs':&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168763"><span class="hs-identifier hs-var">tvs'</span></a></span><span>
</span><span id="line-680"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;mb_deriv_strat':&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc) -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168760"><span class="hs-identifier hs-var">mb_deriv_strat'</span></a></span><span>
</span><span id="line-681"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;deriv_ctxt':&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DerivContext -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168762"><span class="hs-identifier hs-var">deriv_ctxt'</span></a></span><span>
</span><span id="line-682"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cls:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Class -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168768"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-683"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;inst_tys':&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168761"><span class="hs-identifier hs-var">inst_tys'</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-684"></span><span>                </span><span class="hs-comment">-- C.f. GHC.Tc.TyCl.Instance.tcLocalInstDecl1</span><span>
</span><span id="line-685"></span><span>
</span><span id="line-686"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Class -&gt; Name
</span><a href="GHC.Core.Class.html#className"><span class="hs-identifier hs-var hs-var">className</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168768"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">Name -&gt; Name -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="GHC.Builtin.Names.html#typeableClassName"><span class="hs-identifier hs-var">typeableClassName</span></a></span><span>
</span><span id="line-687"></span><span>         </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TcRn ()
</span><a href="GHC.Tc.Deriv.html#warnUselessTypeable"><span class="hs-identifier hs-var">warnUselessTypeable</span></a></span><span>
</span><span id="line-688"></span><span>                 </span><span class="annot"><span class="annottext">Maybe EarlyDerivSpec
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe EarlyDerivSpec
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-689"></span><span>         </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">EarlyDerivSpec -&gt; Maybe EarlyDerivSpec
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">(EarlyDerivSpec -&gt; Maybe EarlyDerivSpec)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) EarlyDerivSpec
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Maybe EarlyDerivSpec)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe OverlapMode
-&gt; [TyVar]
-&gt; Class
-&gt; [PredType]
-&gt; DerivContext
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mkEqnHelp"><span class="hs-identifier hs-var">mkEqnHelp</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Located OverlapMode -&gt; OverlapMode)
-&gt; Maybe (Located OverlapMode) -&gt; Maybe OverlapMode
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">Located OverlapMode -&gt; OverlapMode
forall l e. GenLocated l e -&gt; e
</span><a href="GHC.Types.SrcLoc.html#unLoc"><span class="hs-identifier hs-var">unLoc</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (Located OverlapMode)
</span><a href="#local-6989586621681168776"><span class="hs-identifier hs-var">overlap_mode</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-690"></span><span>                                 </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168763"><span class="hs-identifier hs-var">tvs'</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168768"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168761"><span class="hs-identifier hs-var">inst_tys'</span></a></span><span>
</span><span id="line-691"></span><span>                                 </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168762"><span class="hs-identifier hs-var">deriv_ctxt'</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168760"><span class="hs-identifier hs-var">mb_deriv_strat'</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-692"></span><span>
</span><span id="line-693"></span><span class="hs-comment">-- Typecheck the type in a standalone deriving declaration.</span><span>
</span><span id="line-694"></span><span class="hs-comment">--</span><span>
</span><span id="line-695"></span><span class="hs-comment">-- This may appear dense, but it's mostly huffing and puffing to recognize</span><span>
</span><span id="line-696"></span><span class="hs-comment">-- the special case of a type with an extra-constraints wildcard context, e.g.,</span><span>
</span><span id="line-697"></span><span class="hs-comment">--</span><span>
</span><span id="line-698"></span><span class="hs-comment">--   deriving instance _ =&gt; Eq (Foo a)</span><span>
</span><span id="line-699"></span><span class="hs-comment">--</span><span>
</span><span id="line-700"></span><span class="hs-comment">-- If there is such a wildcard, we typecheck this as if we had written</span><span>
</span><span id="line-701"></span><span class="hs-comment">-- @deriving instance Eq (Foo a)@, and return @'InferContext' ('Just' loc)@,</span><span>
</span><span id="line-702"></span><span class="hs-comment">-- as the 'DerivContext', where loc is the location of the wildcard used for</span><span>
</span><span id="line-703"></span><span class="hs-comment">-- error reporting. This indicates that we should infer the context as if we</span><span>
</span><span id="line-704"></span><span class="hs-comment">-- were deriving Eq via a deriving clause</span><span>
</span><span id="line-705"></span><span class="hs-comment">-- (see Note [Inferring the instance context] in GHC.Tc.Deriv.Infer).</span><span>
</span><span id="line-706"></span><span class="hs-comment">--</span><span>
</span><span id="line-707"></span><span class="hs-comment">-- If there is no wildcard, then proceed as normal, and instead return</span><span>
</span><span id="line-708"></span><span class="hs-comment">-- @'SupplyContext' theta@, where theta is the typechecked context.</span><span>
</span><span id="line-709"></span><span class="hs-comment">--</span><span>
</span><span id="line-710"></span><span class="hs-comment">-- Note that this will never return @'InferContext' 'Nothing'@, as that can</span><span>
</span><span id="line-711"></span><span class="hs-comment">-- only happen with @deriving@ clauses.</span><span>
</span><span id="line-712"></span><span class="annot"><a href="GHC.Tc.Deriv.html#tcStandaloneDerivInstType"><span class="hs-identifier hs-type">tcStandaloneDerivInstType</span></a></span><span>
</span><span id="line-713"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Origin.html#UserTypeCtxt"><span class="hs-identifier hs-type">UserTypeCtxt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Hs.Type.html#LHsSigWcType"><span class="hs-identifier hs-type">LHsSigWcType</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span>
</span><span id="line-714"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivContext"><span class="hs-identifier hs-type">DerivContext</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-715"></span><span id="tcStandaloneDerivInstType"><span class="annot"><span class="annottext">tcStandaloneDerivInstType :: UserTypeCtxt
-&gt; LHsSigWcType GhcRn
-&gt; TcM ([TyVar], DerivContext, Class, [PredType])
</span><a href="GHC.Tc.Deriv.html#tcStandaloneDerivInstType"><span class="hs-identifier hs-var hs-var">tcStandaloneDerivInstType</span></a></span></span><span> </span><span id="local-6989586621681168722"><span class="annot"><span class="annottext">UserTypeCtxt
</span><a href="#local-6989586621681168722"><span class="hs-identifier hs-var">ctxt</span></a></span></span><span>
</span><span id="line-716"></span><span>    </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Type.html#HsWC"><span class="hs-identifier hs-type">HsWC</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">hswc_body :: forall pass thing. HsWildCardBndrs pass thing -&gt; thing
</span><a href="GHC.Hs.Type.html#hswc_body"><span class="hs-identifier hs-var">hswc_body</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168719"><span class="annot"><span class="annottext">deriv_ty :: LHsSigType GhcRn
</span><a href="#local-6989586621681168719"><span class="hs-identifier hs-var">deriv_ty</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Type.html#HsIB"><span class="hs-identifier hs-type">HsIB</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">hsib_ext :: forall pass thing. HsImplicitBndrs pass thing -&gt; XHsIB pass thing
</span><a href="GHC.Hs.Type.html#hsib_ext"><span class="hs-identifier hs-var">hsib_ext</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168716"><span class="annot"><span class="annottext">XHsIB GhcRn (GenLocated SrcSpan (HsType GhcRn))
</span><a href="#local-6989586621681168716"><span class="hs-identifier hs-var">vars</span></a></span></span><span>
</span><span id="line-717"></span><span>                                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">hsib_body :: forall pass thing. HsImplicitBndrs pass thing -&gt; thing
</span><a href="GHC.Hs.Type.html#hsib_body"><span class="hs-identifier hs-var">hsib_body</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168714"><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn)
</span><a href="#local-6989586621681168714"><span class="hs-identifier hs-var">deriv_ty_body</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-718"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168713"><span class="annot"><span class="annottext">[LHsTyVarBndr Specificity GhcRn]
</span><a href="#local-6989586621681168713"><span class="hs-identifier hs-var">tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168712"><span class="annot"><span class="annottext">LHsContext GhcRn
</span><a href="#local-6989586621681168712"><span class="hs-identifier hs-var">theta</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168711"><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn)
</span><a href="#local-6989586621681168711"><span class="hs-identifier hs-var">rho</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn)
-&gt; ([LHsTyVarBndr Specificity GhcRn], LHsContext GhcRn,
    GenLocated SrcSpan (HsType GhcRn))
forall pass.
LHsType pass
-&gt; ([LHsTyVarBndr Specificity pass], LHsContext pass, LHsType pass)
</span><a href="GHC.Hs.Type.html#splitLHsSigmaTyInvis"><span class="hs-identifier hs-var">splitLHsSigmaTyInvis</span></a></span><span> </span><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn)
</span><a href="#local-6989586621681168714"><span class="hs-identifier hs-var">deriv_ty_body</span></a></span><span>
</span><span id="line-719"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">[</span><span id="local-6989586621681168709"><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn)
</span><a href="#local-6989586621681168709"><span class="hs-identifier hs-var">wc_pred</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">LHsContext GhcRn
</span><a href="#local-6989586621681168712"><span class="hs-identifier hs-var">theta</span></a></span><span>
</span><span id="line-720"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span id="local-6989586621681168708"><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168708"><span class="hs-identifier hs-var">wc_span</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Type.html#HsWildCardTy"><span class="hs-identifier hs-type">HsWildCardTy</span></a></span><span> </span><span class="annot"><span class="annottext">XWildCardTy GhcRn
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn)
-&gt; GenLocated SrcSpan (HsType GhcRn)
forall pass. LHsType pass -&gt; LHsType pass
</span><a href="GHC.Hs.Type.html#ignoreParens"><span class="hs-identifier hs-var">ignoreParens</span></a></span><span> </span><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn)
</span><a href="#local-6989586621681168709"><span class="hs-identifier hs-var">wc_pred</span></a></span><span>
</span><span id="line-721"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621681168705"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168705"><span class="hs-identifier hs-var">dfun_ty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">UserTypeCtxt -&gt; LHsSigType GhcRn -&gt; TcM PredType
</span><a href="GHC.Tc.Gen.HsType.html#tcHsClsInstType"><span class="hs-identifier hs-var">tcHsClsInstType</span></a></span><span> </span><span class="annot"><span class="annottext">UserTypeCtxt
</span><a href="#local-6989586621681168722"><span class="hs-identifier hs-var">ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">(LHsSigType GhcRn -&gt; TcM PredType)
-&gt; LHsSigType GhcRn -&gt; TcM PredType
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-722"></span><span>                  </span><span class="annot"><span class="annottext">HsIB :: forall pass thing.
XHsIB pass thing -&gt; thing -&gt; HsImplicitBndrs pass thing
</span><a href="GHC.Hs.Type.html#HsIB"><span class="hs-identifier hs-type">HsIB</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">hsib_ext :: XHsIB GhcRn (GenLocated SrcSpan (HsType GhcRn))
</span><a href="GHC.Hs.Type.html#hsib_ext"><span class="hs-identifier hs-var">hsib_ext</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">XHsIB GhcRn (GenLocated SrcSpan (HsType GhcRn))
</span><a href="#local-6989586621681168716"><span class="hs-identifier hs-var">vars</span></a></span><span>
</span><span id="line-723"></span><span>                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">hsib_body :: GenLocated SrcSpan (HsType GhcRn)
</span><a href="GHC.Hs.Type.html#hsib_body"><span class="hs-identifier hs-var">hsib_body</span></a></span><span>
</span><span id="line-724"></span><span>                           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SrcSpan -&gt; HsType GhcRn -&gt; GenLocated SrcSpan (HsType GhcRn)
forall l e. l -&gt; e -&gt; GenLocated l e
</span><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-var">L</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn) -&gt; SrcSpan
forall l e. GenLocated l e -&gt; l
</span><a href="GHC.Types.SrcLoc.html#getLoc"><span class="hs-identifier hs-var">getLoc</span></a></span><span> </span><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn)
</span><a href="#local-6989586621681168714"><span class="hs-identifier hs-var">deriv_ty_body</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(HsType GhcRn -&gt; GenLocated SrcSpan (HsType GhcRn))
-&gt; HsType GhcRn -&gt; GenLocated SrcSpan (HsType GhcRn)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-725"></span><span>                             </span><span class="annot"><span class="annottext">HsForAllTy :: forall pass.
XForAllTy pass
-&gt; HsForAllTelescope pass -&gt; LHsType pass -&gt; HsType pass
</span><a href="GHC.Hs.Type.html#HsForAllTy"><span class="hs-identifier hs-type">HsForAllTy</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">hst_tele :: HsForAllTelescope GhcRn
</span><a href="GHC.Hs.Type.html#hst_tele"><span class="hs-identifier hs-var">hst_tele</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[LHsTyVarBndr Specificity GhcRn] -&gt; HsForAllTelescope GhcRn
forall (p :: Pass).
[LHsTyVarBndr Specificity (GhcPass p)]
-&gt; HsForAllTelescope (GhcPass p)
</span><a href="GHC.Hs.Type.html#mkHsForAllInvisTele"><span class="hs-identifier hs-var">mkHsForAllInvisTele</span></a></span><span> </span><span class="annot"><span class="annottext">[LHsTyVarBndr Specificity GhcRn]
</span><a href="#local-6989586621681168713"><span class="hs-identifier hs-var">tvs</span></a></span><span>
</span><span id="line-726"></span><span>                                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">hst_xforall :: XForAllTy GhcRn
</span><a href="GHC.Hs.Type.html#hst_xforall"><span class="hs-identifier hs-var">hst_xforall</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NoExtField
XForAllTy GhcRn
</span><a href="GHC.Hs.Extension.html#noExtField"><span class="hs-identifier hs-var">noExtField</span></a></span><span>
</span><span id="line-727"></span><span>                                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">hst_body :: GenLocated SrcSpan (HsType GhcRn)
</span><a href="GHC.Hs.Type.html#hst_body"><span class="hs-identifier hs-var">hst_body</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">GenLocated SrcSpan (HsType GhcRn)
</span><a href="#local-6989586621681168711"><span class="hs-identifier hs-var">rho</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">}</span><span>
</span><span id="line-728"></span><span>       </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168698"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168698"><span class="hs-identifier hs-var">tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168697"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168697"><span class="hs-identifier hs-var">_theta</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168696"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168696"><span class="hs-identifier hs-var">cls</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168695"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168695"><span class="hs-identifier hs-var">inst_tys</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PredType -&gt; ([TyVar], [PredType], Class, [PredType])
</span><a href="GHC.Tc.Utils.TcType.html#tcSplitDFunTy"><span class="hs-identifier hs-var">tcSplitDFunTy</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168705"><span class="hs-identifier hs-var">dfun_ty</span></a></span><span>
</span><span id="line-729"></span><span>       </span><span class="annot"><span class="annottext">([TyVar], DerivContext, Class, [PredType])
-&gt; TcM ([TyVar], DerivContext, Class, [PredType])
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168698"><span class="hs-identifier hs-var">tvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe SrcSpan -&gt; DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#InferContext"><span class="hs-identifier hs-var">InferContext</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SrcSpan -&gt; Maybe SrcSpan
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168708"><span class="hs-identifier hs-var">wc_span</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168696"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168695"><span class="hs-identifier hs-var">inst_tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-730"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-731"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621681168693"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168693"><span class="hs-identifier hs-var">dfun_ty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">UserTypeCtxt -&gt; LHsSigType GhcRn -&gt; TcM PredType
</span><a href="GHC.Tc.Gen.HsType.html#tcHsClsInstType"><span class="hs-identifier hs-var">tcHsClsInstType</span></a></span><span> </span><span class="annot"><span class="annottext">UserTypeCtxt
</span><a href="#local-6989586621681168722"><span class="hs-identifier hs-var">ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigType GhcRn
</span><a href="#local-6989586621681168719"><span class="hs-identifier hs-var">deriv_ty</span></a></span><span>
</span><span id="line-732"></span><span>       </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168692"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168692"><span class="hs-identifier hs-var">tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168691"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168691"><span class="hs-identifier hs-var">theta</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168690"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168690"><span class="hs-identifier hs-var">cls</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168689"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168689"><span class="hs-identifier hs-var">inst_tys</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PredType -&gt; ([TyVar], [PredType], Class, [PredType])
</span><a href="GHC.Tc.Utils.TcType.html#tcSplitDFunTy"><span class="hs-identifier hs-var">tcSplitDFunTy</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168693"><span class="hs-identifier hs-var">dfun_ty</span></a></span><span>
</span><span id="line-733"></span><span>       </span><span class="annot"><span class="annottext">([TyVar], DerivContext, Class, [PredType])
-&gt; TcM ([TyVar], DerivContext, Class, [PredType])
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168692"><span class="hs-identifier hs-var">tvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#SupplyContext"><span class="hs-identifier hs-var">SupplyContext</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168691"><span class="hs-identifier hs-var">theta</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168690"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168689"><span class="hs-identifier hs-var">inst_tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-734"></span><span>
</span><span id="line-735"></span><span class="annot"><a href="GHC.Tc.Deriv.html#warnUselessTypeable"><span class="hs-identifier hs-type">warnUselessTypeable</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-736"></span><span id="warnUselessTypeable"><span class="annot"><span class="annottext">warnUselessTypeable :: TcRn ()
</span><a href="GHC.Tc.Deriv.html#warnUselessTypeable"><span class="hs-identifier hs-var hs-var">warnUselessTypeable</span></a></span></span><span>
</span><span id="line-737"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681168688"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168688"><span class="hs-identifier hs-var">warn</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">WarningFlag -&gt; TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. WarningFlag -&gt; TcRnIf gbl lcl Bool
</span><a href="GHC.Tc.Utils.Monad.html#woptM"><span class="hs-identifier hs-var">woptM</span></a></span><span> </span><span class="annot"><span class="annottext">WarningFlag
</span><a href="GHC.Driver.Flags.html#Opt_WarnDerivingTypeable"><span class="hs-identifier hs-var">Opt_WarnDerivingTypeable</span></a></span><span>
</span><span id="line-738"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; TcRn () -&gt; TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168688"><span class="hs-identifier hs-var">warn</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; TcRn ()) -&gt; TcRn () -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">WarnReason -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#addWarnTc"><span class="hs-identifier hs-var">addWarnTc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">WarningFlag -&gt; WarnReason
</span><a href="GHC.Driver.Flags.html#Reason"><span class="hs-identifier hs-var">Reason</span></a></span><span> </span><span class="annot"><span class="annottext">WarningFlag
</span><a href="GHC.Driver.Flags.html#Opt_WarnDerivingTypeable"><span class="hs-identifier hs-var">Opt_WarnDerivingTypeable</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-739"></span><span>                   </span><span class="annot"><span class="annottext">(SDoc -&gt; TcRn ()) -&gt; SDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Deriving&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Name -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="GHC.Builtin.Names.html#typeableClassName"><span class="hs-identifier hs-var">typeableClassName</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-740"></span><span>                     </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;has no effect: all types now auto-derive Typeable&quot;</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-741"></span><span>
</span><span id="line-742"></span><span class="hs-comment">------------------------------------------------------------------</span><span>
</span><span id="line-743"></span><span class="annot"><a href="GHC.Tc.Deriv.html#deriveTyData"><span class="hs-identifier hs-type">deriveTyData</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- LHS of data or data instance</span><span>
</span><span id="line-744"></span><span>                    </span><span class="hs-comment">-- Can be a data instance, hence [Type] args</span><span>
</span><span id="line-745"></span><span>                    </span><span class="hs-comment">-- and in that case the TyCon is the /family/ tycon</span><span>
</span><span id="line-746"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#DerivStrategy"><span class="hs-identifier hs-type">DerivStrategy</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- The optional deriving strategy</span><span>
</span><span id="line-747"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- The type variables bound by the derived class</span><span>
</span><span id="line-748"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span>   </span><span class="hs-comment">-- The derived class</span><span>
</span><span id="line-749"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- The derived class's arguments</span><span>
</span><span id="line-750"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Kind"><span class="hs-identifier hs-type">Kind</span></a></span><span>    </span><span class="hs-comment">-- The function argument in the derived class's kind.</span><span>
</span><span id="line-751"></span><span>                        </span><span class="hs-comment">-- (e.g., if `deriving Functor`, this would be</span><span>
</span><span id="line-752"></span><span>                        </span><span class="hs-comment">-- `Type -&gt; Type` since</span><span>
</span><span id="line-753"></span><span>                        </span><span class="hs-comment">-- `Functor :: (Type -&gt; Type) -&gt; Constraint`)</span><span>
</span><span id="line-754"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-755"></span><span class="hs-comment">-- The deriving clause of a data or newtype declaration</span><span>
</span><span id="line-756"></span><span class="hs-comment">-- I.e. not standalone deriving</span><span>
</span><span id="line-757"></span><span id="deriveTyData"><span class="annot"><span class="annottext">deriveTyData :: TyCon
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; [TyVar]
-&gt; Class
-&gt; [PredType]
-&gt; PredType
-&gt; IOEnv (Env TcGblEnv TcLclEnv) EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#deriveTyData"><span class="hs-identifier hs-var hs-var">deriveTyData</span></a></span></span><span> </span><span id="local-6989586621681168681"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168681"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681168680"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168680"><span class="hs-identifier hs-var">tc_args</span></a></span></span><span> </span><span id="local-6989586621681168679"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168679"><span class="hs-identifier hs-var">mb_deriv_strat</span></a></span></span><span> </span><span id="local-6989586621681168678"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168678"><span class="hs-identifier hs-var">deriv_tvs</span></a></span></span><span> </span><span id="local-6989586621681168677"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168677"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621681168676"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168676"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span> </span><span id="local-6989586621681168675"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168675"><span class="hs-identifier hs-var">cls_arg_kind</span></a></span></span><span>
</span><span id="line-758"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span>  </span><span class="hs-comment">-- Given data T a b c = ... deriving( C d ),</span><span>
</span><span id="line-759"></span><span>           </span><span class="hs-comment">-- we want to drop type variables from T so that (C d (T a)) is well-kinded</span><span>
</span><span id="line-760"></span><span>          </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168674"><span class="annot"><span class="annottext">[Scaled PredType]
</span><a href="#local-6989586621681168674"><span class="hs-identifier hs-var">arg_kinds</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">PredType
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PredType -&gt; ([Scaled PredType], PredType)
</span><a href="GHC.Core.Type.html#splitFunTys"><span class="hs-identifier hs-var">splitFunTys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168675"><span class="hs-identifier hs-var">cls_arg_kind</span></a></span><span>
</span><span id="line-761"></span><span>              </span><span id="local-6989586621681168672"><span class="annot"><span class="annottext">n_args_to_drop :: Arity
</span><a href="#local-6989586621681168672"><span class="hs-identifier hs-var hs-var">n_args_to_drop</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Scaled PredType] -&gt; Arity
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Arity
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[Scaled PredType]
</span><a href="#local-6989586621681168674"><span class="hs-identifier hs-var">arg_kinds</span></a></span><span>
</span><span id="line-762"></span><span>              </span><span id="local-6989586621681168670"><span class="annot"><span class="annottext">n_args_to_keep :: Arity
</span><a href="#local-6989586621681168670"><span class="hs-identifier hs-var hs-var">n_args_to_keep</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; Arity
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Arity
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168680"><span class="hs-identifier hs-var">tc_args</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Arity
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621681168672"><span class="hs-identifier hs-var">n_args_to_drop</span></a></span><span>
</span><span id="line-763"></span><span>                                </span><span class="hs-comment">-- See Note [tc_args and tycon arity]</span><span>
</span><span id="line-764"></span><span>              </span><span class="hs-special">(</span><span id="local-6989586621681168669"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168669"><span class="hs-identifier hs-var">tc_args_to_keep</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168668"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168668"><span class="hs-identifier hs-var">args_to_drop</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-765"></span><span>                              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; [PredType] -&gt; ([PredType], [PredType])
forall a. Arity -&gt; [a] -&gt; ([a], [a])
</span><a href="../../base/src/GHC.List.html#splitAt"><span class="hs-identifier hs-var">splitAt</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621681168670"><span class="hs-identifier hs-var">n_args_to_keep</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168680"><span class="hs-identifier hs-var">tc_args</span></a></span><span>
</span><span id="line-766"></span><span>              </span><span id="local-6989586621681168666"><span class="annot"><span class="annottext">inst_ty_kind :: PredType
</span><a href="#local-6989586621681168666"><span class="hs-identifier hs-var hs-var">inst_ty_kind</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; PredType -&gt; PredType
PredType -&gt; PredType
</span><a href="GHC.Core.Type.html#tcTypeKind"><span class="hs-identifier hs-var">tcTypeKind</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [PredType] -&gt; PredType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168681"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168669"><span class="hs-identifier hs-var">tc_args_to_keep</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-767"></span><span>
</span><span id="line-768"></span><span>              </span><span class="hs-comment">-- Match up the kinds, and apply the resulting kind substitution</span><span>
</span><span id="line-769"></span><span>              </span><span class="hs-comment">-- to the types.  See Note [Unify kinds in deriving]</span><span>
</span><span id="line-770"></span><span>              </span><span class="hs-comment">-- We are assuming the tycon tyvars and the class tyvars are distinct</span><span>
</span><span id="line-771"></span><span>              </span><span id="local-6989586621681168665"><span class="annot"><span class="annottext">mb_match :: Maybe TCvSubst
</span><a href="#local-6989586621681168665"><span class="hs-identifier hs-var hs-var">mb_match</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PredType -&gt; PredType -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcUnifyTy"><span class="hs-identifier hs-var">tcUnifyTy</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168666"><span class="hs-identifier hs-var">inst_ty_kind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168675"><span class="hs-identifier hs-var">cls_arg_kind</span></a></span><span>
</span><span id="line-772"></span><span>              </span><span id="local-6989586621681168664"><span class="annot"><span class="annottext">enough_args :: Bool
</span><a href="#local-6989586621681168664"><span class="hs-identifier hs-var hs-var">enough_args</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621681168670"><span class="hs-identifier hs-var">n_args_to_keep</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;=</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span>
</span><span id="line-773"></span><span>
</span><span id="line-774"></span><span>        </span><span class="hs-comment">-- Check that the result really is well-kinded</span><span>
</span><span id="line-775"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#checkTc"><span class="hs-identifier hs-var">checkTc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168664"><span class="hs-identifier hs-var">enough_args</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="#local-6989586621681168665"><span class="hs-identifier hs-var">mb_match</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-776"></span><span>                  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Class -&gt; [PredType] -&gt; PredType -&gt; Bool -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingKindErr"><span class="hs-identifier hs-var">derivingKindErr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168681"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168677"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168676"><span class="hs-identifier hs-var">cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168675"><span class="hs-identifier hs-var">cls_arg_kind</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168664"><span class="hs-identifier hs-var">enough_args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-777"></span><span>
</span><span id="line-778"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-comment">-- Returns a singleton-element list if using ViaStrategy and an</span><span>
</span><span id="line-779"></span><span>              </span><span class="hs-comment">-- empty list otherwise. Useful for free-variable calculations.</span><span>
</span><span id="line-780"></span><span>              </span><span class="annot"><a href="#local-6989586621681168662"><span class="hs-identifier hs-type">deriv_strat_tys</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#DerivStrategy"><span class="hs-identifier hs-type">DerivStrategy</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-781"></span><span>              </span><span id="local-6989586621681168662"><span class="annot"><span class="annottext">deriv_strat_tys :: Maybe (DerivStrategy GhcTc) -&gt; [PredType]
</span><a href="#local-6989586621681168662"><span class="hs-identifier hs-var hs-var">deriv_strat_tys</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(DerivStrategy GhcTc -&gt; [PredType])
-&gt; Maybe (DerivStrategy GhcTc) -&gt; [PredType]
forall (t :: * -&gt; *) m a.
(Foldable t, Monoid m) =&gt;
(a -&gt; m) -&gt; t a -&gt; m
</span><a href="../../base/src/Data.Foldable.html#foldMap"><span class="hs-identifier hs-var">foldMap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[PredType]
-&gt; (XViaStrategy GhcTc -&gt; [PredType])
-&gt; DerivStrategy GhcTc
-&gt; [PredType]
forall p (pass :: Pass) r.
(p ~ GhcPass pass) =&gt;
r -&gt; (XViaStrategy p -&gt; r) -&gt; DerivStrategy p -&gt; r
</span><a href="GHC.Hs.Decls.html#foldDerivStrategy"><span class="hs-identifier hs-var">foldDerivStrategy</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PredType -&gt; [PredType] -&gt; [PredType]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-782"></span><span>
</span><span id="line-783"></span><span>              </span><span id="local-6989586621681168649"><span class="annot"><span class="annottext">propagate_subst :: TCvSubst
-&gt; [TyVar]
-&gt; [PredType]
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; ([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
</span><a href="#local-6989586621681168649"><span class="hs-identifier hs-var hs-var">propagate_subst</span></a></span></span><span> </span><span id="local-6989586621681168648"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168648"><span class="hs-identifier hs-var">kind_subst</span></a></span></span><span> </span><span id="local-6989586621681168647"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168647"><span class="hs-identifier hs-var">tkvs'</span></a></span></span><span> </span><span id="local-6989586621681168646"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168646"><span class="hs-identifier hs-var">cls_tys'</span></a></span></span><span> </span><span id="local-6989586621681168645"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168645"><span class="hs-identifier hs-var">tc_args'</span></a></span></span><span> </span><span id="local-6989586621681168644"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168644"><span class="hs-identifier hs-var">mb_deriv_strat'</span></a></span></span><span>
</span><span id="line-784"></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168643"><span class="hs-identifier hs-var">final_tkvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168642"><span class="hs-identifier hs-var">final_cls_tys</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168641"><span class="hs-identifier hs-var">final_tc_args</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168640"><span class="hs-identifier hs-var">final_mb_deriv_strat</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-785"></span><span>                </span><span class="hs-keyword">where</span><span>
</span><span id="line-786"></span><span>                  </span><span id="local-6989586621681168639"><span class="annot"><span class="annottext">ki_subst_range :: VarSet
</span><a href="#local-6989586621681168639"><span class="hs-identifier hs-var hs-var">ki_subst_range</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TCvSubst -&gt; VarSet
</span><a href="GHC.Core.TyCo.Subst.html#getTCvSubstRangeFVs"><span class="hs-identifier hs-var">getTCvSubstRangeFVs</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168648"><span class="hs-identifier hs-var">kind_subst</span></a></span><span>
</span><span id="line-787"></span><span>                  </span><span class="hs-comment">-- See Note [Unification of two kind variables in deriving]</span><span>
</span><span id="line-788"></span><span>                  </span><span id="local-6989586621681168638"><span class="annot"><span class="annottext">unmapped_tkvs :: [TyVar]
</span><a href="#local-6989586621681168638"><span class="hs-identifier hs-var hs-var">unmapped_tkvs</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TyVar -&gt; Bool) -&gt; [TyVar] -&gt; [TyVar]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621681168637"><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621681168637"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621681168637"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; TCvSubst -&gt; Bool
</span><a href="GHC.Core.TyCo.Subst.html#notElemTCvSubst"><span class="hs-operator hs-var">`notElemTCvSubst`</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168648"><span class="hs-identifier hs-var">kind_subst</span></a></span><span>
</span><span id="line-789"></span><span>                                         </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621681168637"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#elemVarSet"><span class="hs-operator hs-var">`elemVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621681168639"><span class="hs-identifier hs-var">ki_subst_range</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-790"></span><span>                                           </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168647"><span class="hs-identifier hs-var">tkvs'</span></a></span><span>
</span><span id="line-791"></span><span>                  </span><span class="hs-special">(</span><span id="local-6989586621681168636"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168636"><span class="hs-identifier hs-var">subst</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; [TyVar] -&gt; (TCvSubst, [TyVar])
TCvSubst -&gt; [TyVar] -&gt; (TCvSubst, [TyVar])
</span><a href="GHC.Core.TyCo.Subst.html#substTyVarBndrs"><span class="hs-identifier hs-var">substTyVarBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168648"><span class="hs-identifier hs-var">kind_subst</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168638"><span class="hs-identifier hs-var">unmapped_tkvs</span></a></span><span>
</span><span id="line-792"></span><span>                  </span><span id="local-6989586621681168641"><span class="annot"><span class="annottext">final_tc_args :: [PredType]
</span><a href="#local-6989586621681168641"><span class="hs-identifier hs-var hs-var">final_tc_args</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; [PredType] -&gt; [PredType]
TCvSubst -&gt; [PredType] -&gt; [PredType]
</span><a href="GHC.Core.TyCo.Subst.html#substTys"><span class="hs-identifier hs-var">substTys</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168636"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168645"><span class="hs-identifier hs-var">tc_args'</span></a></span><span>
</span><span id="line-793"></span><span>                  </span><span id="local-6989586621681168642"><span class="annot"><span class="annottext">final_cls_tys :: [PredType]
</span><a href="#local-6989586621681168642"><span class="hs-identifier hs-var hs-var">final_cls_tys</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; [PredType] -&gt; [PredType]
TCvSubst -&gt; [PredType] -&gt; [PredType]
</span><a href="GHC.Core.TyCo.Subst.html#substTys"><span class="hs-identifier hs-var">substTys</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168636"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168646"><span class="hs-identifier hs-var">cls_tys'</span></a></span><span>
</span><span id="line-794"></span><span>                  </span><span id="local-6989586621681168640"><span class="annot"><span class="annottext">final_mb_deriv_strat :: Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168640"><span class="hs-identifier hs-var hs-var">final_mb_deriv_strat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(DerivStrategy GhcTc -&gt; DerivStrategy GhcTc)
-&gt; Maybe (DerivStrategy GhcTc) -&gt; Maybe (DerivStrategy GhcTc)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(XViaStrategy GhcTc -&gt; XViaStrategy GhcTc)
-&gt; DerivStrategy GhcTc -&gt; DerivStrategy GhcTc
forall p (pass :: Pass).
(p ~ GhcPass pass) =&gt;
(XViaStrategy p -&gt; XViaStrategy p)
-&gt; DerivStrategy p -&gt; DerivStrategy p
</span><a href="GHC.Hs.Decls.html#mapDerivStrategy"><span class="hs-identifier hs-var">mapDerivStrategy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; PredType -&gt; PredType
TCvSubst -&gt; PredType -&gt; PredType
</span><a href="GHC.Core.TyCo.Subst.html#substTy"><span class="hs-identifier hs-var">substTy</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168636"><span class="hs-identifier hs-var">subst</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-795"></span><span>                                              </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168644"><span class="hs-identifier hs-var">mb_deriv_strat'</span></a></span><span>
</span><span id="line-796"></span><span>                  </span><span class="hs-comment">-- See Note [Floating `via` type variables]</span><span>
</span><span id="line-797"></span><span>                  </span><span id="local-6989586621681168643"><span class="annot"><span class="annottext">final_tkvs :: [TyVar]
</span><a href="#local-6989586621681168643"><span class="hs-identifier hs-var hs-var">final_tkvs</span></a></span></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; [TyVar]
</span><a href="GHC.Core.TyCo.FVs.html#tyCoVarsOfTypesWellScoped"><span class="hs-identifier hs-var">tyCoVarsOfTypesWellScoped</span></a></span><span> </span><span class="annot"><span class="annottext">([PredType] -&gt; [TyVar]) -&gt; [PredType] -&gt; [TyVar]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-798"></span><span>                                         </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168642"><span class="hs-identifier hs-var">final_cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; [PredType] -&gt; [PredType]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168641"><span class="hs-identifier hs-var">final_tc_args</span></a></span><span>
</span><span id="line-799"></span><span>                                           </span><span class="annot"><span class="annottext">[PredType] -&gt; [PredType] -&gt; [PredType]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc) -&gt; [PredType]
</span><a href="#local-6989586621681168662"><span class="hs-identifier hs-var">deriv_strat_tys</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168640"><span class="hs-identifier hs-var">final_mb_deriv_strat</span></a></span><span>
</span><span id="line-800"></span><span>
</span><span id="line-801"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168634"><span class="annot"><span class="annottext">tkvs :: [TyVar]
</span><a href="#local-6989586621681168634"><span class="hs-identifier hs-var hs-var">tkvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; [TyVar]
</span><a href="GHC.Core.TyCo.FVs.html#scopedSort"><span class="hs-identifier hs-var">scopedSort</span></a></span><span> </span><span class="annot"><span class="annottext">([TyVar] -&gt; [TyVar]) -&gt; [TyVar] -&gt; [TyVar]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">FV -&gt; [TyVar]
</span><a href="GHC.Utils.FV.html#fvVarList"><span class="hs-identifier hs-var">fvVarList</span></a></span><span> </span><span class="annot"><span class="annottext">(FV -&gt; [TyVar]) -&gt; FV -&gt; [TyVar]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-802"></span><span>                     </span><span class="annot"><span class="annottext">FV -&gt; FV -&gt; FV
</span><a href="GHC.Utils.FV.html#unionFV"><span class="hs-identifier hs-var">unionFV</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[PredType] -&gt; FV
</span><a href="GHC.Core.TyCo.FVs.html#tyCoFVsOfTypes"><span class="hs-identifier hs-var">tyCoFVsOfTypes</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168669"><span class="hs-identifier hs-var">tc_args_to_keep</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-803"></span><span>                             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVar] -&gt; FV
</span><a href="GHC.Utils.FV.html#mkFVs"><span class="hs-identifier hs-var">FV.mkFVs</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168678"><span class="hs-identifier hs-var">deriv_tvs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-804"></span><span>              </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681168631"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168631"><span class="hs-identifier hs-var">kind_subst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="#local-6989586621681168665"><span class="hs-identifier hs-var">mb_match</span></a></span><span>
</span><span id="line-805"></span><span>              </span><span class="hs-special">(</span><span id="local-6989586621681168630"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168630"><span class="hs-identifier hs-var">tkvs'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168629"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168629"><span class="hs-identifier hs-var">cls_tys'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168628"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168628"><span class="hs-identifier hs-var">tc_args'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168627"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168627"><span class="hs-identifier hs-var">mb_deriv_strat'</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-806"></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TCvSubst
-&gt; [TyVar]
-&gt; [PredType]
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; ([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
</span><a href="#local-6989586621681168649"><span class="hs-identifier hs-var">propagate_subst</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168631"><span class="hs-identifier hs-var">kind_subst</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168634"><span class="hs-identifier hs-var">tkvs</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168676"><span class="hs-identifier hs-var">cls_tys</span></a></span><span>
</span><span id="line-807"></span><span>                                  </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168669"><span class="hs-identifier hs-var">tc_args_to_keep</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168679"><span class="hs-identifier hs-var">mb_deriv_strat</span></a></span><span>
</span><span id="line-808"></span><span>
</span><span id="line-809"></span><span>          </span><span class="hs-comment">-- See Note [Unify kinds in deriving]</span><span>
</span><span id="line-810"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168626"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168626"><span class="hs-identifier hs-var">final_tkvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168625"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168625"><span class="hs-identifier hs-var">final_cls_tys</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168624"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168624"><span class="hs-identifier hs-var">final_tc_args</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168623"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168623"><span class="hs-identifier hs-var">final_mb_deriv_strat</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-811"></span><span>            </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168627"><span class="hs-identifier hs-var">mb_deriv_strat'</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-812"></span><span>              </span><span class="hs-comment">-- Perform an additional unification with the kind of the `via`</span><span>
</span><span id="line-813"></span><span>              </span><span class="hs-comment">-- type and the result of the previous kind unification.</span><span>
</span><span id="line-814"></span><span>              </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#ViaStrategy"><span class="hs-identifier hs-type">ViaStrategy</span></a></span><span> </span><span id="local-6989586621681168622"><span class="annot"><span class="annottext">XViaStrategy GhcTc
</span><a href="#local-6989586621681168622"><span class="hs-identifier hs-var">via_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-815"></span><span>                </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168621"><span class="annot"><span class="annottext">via_kind :: PredType
</span><a href="#local-6989586621681168621"><span class="hs-identifier hs-var hs-var">via_kind</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; PredType -&gt; PredType
PredType -&gt; PredType
</span><a href="GHC.Core.Type.html#tcTypeKind"><span class="hs-identifier hs-var">tcTypeKind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
XViaStrategy GhcTc
</span><a href="#local-6989586621681168622"><span class="hs-identifier hs-var">via_ty</span></a></span><span>
</span><span id="line-816"></span><span>                    </span><span id="local-6989586621681168620"><span class="annot"><span class="annottext">inst_ty_kind :: PredType
</span><a href="#local-6989586621681168620"><span class="hs-identifier hs-var hs-var">inst_ty_kind</span></a></span></span><span>
</span><span id="line-817"></span><span>                              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; PredType -&gt; PredType
PredType -&gt; PredType
</span><a href="GHC.Core.Type.html#tcTypeKind"><span class="hs-identifier hs-var">tcTypeKind</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [PredType] -&gt; PredType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168681"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168628"><span class="hs-identifier hs-var">tc_args'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-818"></span><span>                    </span><span id="local-6989586621681168619"><span class="annot"><span class="annottext">via_match :: Maybe TCvSubst
</span><a href="#local-6989586621681168619"><span class="hs-identifier hs-var hs-var">via_match</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PredType -&gt; PredType -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcUnifyTy"><span class="hs-identifier hs-var">tcUnifyTy</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168620"><span class="hs-identifier hs-var">inst_ty_kind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168621"><span class="hs-identifier hs-var">via_kind</span></a></span><span>
</span><span id="line-819"></span><span>
</span><span id="line-820"></span><span>                </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#checkTc"><span class="hs-identifier hs-var">checkTc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe TCvSubst -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="#local-6989586621681168619"><span class="hs-identifier hs-var">via_match</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-821"></span><span>                        </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; PredType -&gt; PredType -&gt; PredType -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingViaKindErr"><span class="hs-identifier hs-var">derivingViaKindErr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168677"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168620"><span class="hs-identifier hs-var">inst_ty_kind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
XViaStrategy GhcTc
</span><a href="#local-6989586621681168622"><span class="hs-identifier hs-var">via_ty</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168621"><span class="hs-identifier hs-var">via_kind</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-822"></span><span>
</span><span id="line-823"></span><span>                </span><span class="hs-keyword">let</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681168618"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168618"><span class="hs-identifier hs-var">via_subst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="#local-6989586621681168619"><span class="hs-identifier hs-var">via_match</span></a></span><span>
</span><span id="line-824"></span><span>                </span><span class="annot"><span class="annottext">([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">(([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
 -&gt; IOEnv
      (Env TcGblEnv TcLclEnv)
      ([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc)))
-&gt; ([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
-&gt; [TyVar]
-&gt; [PredType]
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; ([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
</span><a href="#local-6989586621681168649"><span class="hs-identifier hs-var">propagate_subst</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168618"><span class="hs-identifier hs-var">via_subst</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168630"><span class="hs-identifier hs-var">tkvs'</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168629"><span class="hs-identifier hs-var">cls_tys'</span></a></span><span>
</span><span id="line-825"></span><span>                                       </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168628"><span class="hs-identifier hs-var">tc_args'</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168627"><span class="hs-identifier hs-var">mb_deriv_strat'</span></a></span><span>
</span><span id="line-826"></span><span>
</span><span id="line-827"></span><span>              </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([TyVar], [PredType], [PredType], Maybe (DerivStrategy GhcTc))
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168630"><span class="hs-identifier hs-var">tkvs'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168629"><span class="hs-identifier hs-var">cls_tys'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168628"><span class="hs-identifier hs-var">tc_args'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168627"><span class="hs-identifier hs-var">mb_deriv_strat'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-828"></span><span>
</span><span id="line-829"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;deriveTyData 1&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcRn ()) -&gt; SDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span>
</span><span id="line-830"></span><span>            </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc) -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168623"><span class="hs-identifier hs-var">final_mb_deriv_strat</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprTyVars"><span class="hs-identifier hs-var">pprTyVars</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168678"><span class="hs-identifier hs-var">deriv_tvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168681"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168680"><span class="hs-identifier hs-var">tc_args</span></a></span><span>
</span><span id="line-831"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprTyVars"><span class="hs-identifier hs-var">pprTyVars</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[PredType] -&gt; [TyVar]
</span><a href="GHC.Core.TyCo.FVs.html#tyCoVarsOfTypesList"><span class="hs-identifier hs-var">tyCoVarsOfTypesList</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168680"><span class="hs-identifier hs-var">tc_args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-832"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621681168670"><span class="hs-identifier hs-var">n_args_to_keep</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621681168672"><span class="hs-identifier hs-var">n_args_to_drop</span></a></span><span>
</span><span id="line-833"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">PredType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168666"><span class="hs-identifier hs-var">inst_ty_kind</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">PredType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168675"><span class="hs-identifier hs-var">cls_arg_kind</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="#local-6989586621681168665"><span class="hs-identifier hs-var">mb_match</span></a></span><span>
</span><span id="line-834"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168624"><span class="hs-identifier hs-var">final_tc_args</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168625"><span class="hs-identifier hs-var">final_cls_tys</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-835"></span><span>
</span><span id="line-836"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;deriveTyData 2&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcRn ()) -&gt; SDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span>
</span><span id="line-837"></span><span>            </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168626"><span class="hs-identifier hs-var">final_tkvs</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-838"></span><span>
</span><span id="line-839"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168616"><span class="annot"><span class="annottext">final_tc_app :: PredType
</span><a href="#local-6989586621681168616"><span class="hs-identifier hs-var hs-var">final_tc_app</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [PredType] -&gt; PredType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168681"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168624"><span class="hs-identifier hs-var">final_tc_args</span></a></span><span>
</span><span id="line-840"></span><span>              </span><span id="local-6989586621681168615"><span class="annot"><span class="annottext">final_cls_args :: [PredType]
</span><a href="#local-6989586621681168615"><span class="hs-identifier hs-var hs-var">final_cls_args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168625"><span class="hs-identifier hs-var">final_cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; [PredType] -&gt; [PredType]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168616"><span class="hs-identifier hs-var">final_tc_app</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-841"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#checkTc"><span class="hs-identifier hs-var">checkTc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VarSet -&gt; [PredType] -&gt; Bool
</span><a href="GHC.Tc.Validity.html#allDistinctTyVars"><span class="hs-identifier hs-var">allDistinctTyVars</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVar] -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#mkVarSet"><span class="hs-identifier hs-var">mkVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168626"><span class="hs-identifier hs-var">final_tkvs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168668"><span class="hs-identifier hs-var">args_to_drop</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- (a, b, c)</span><span>
</span><span id="line-842"></span><span>                  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; [PredType] -&gt; PredType -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingEtaErr"><span class="hs-identifier hs-var">derivingEtaErr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168677"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168625"><span class="hs-identifier hs-var">final_cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168616"><span class="hs-identifier hs-var">final_tc_app</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-843"></span><span>                </span><span class="hs-comment">-- Check that</span><span>
</span><span id="line-844"></span><span>                </span><span class="hs-comment">--  (a) The args to drop are all type variables; eg reject:</span><span>
</span><span id="line-845"></span><span>                </span><span class="hs-comment">--              data instance T a Int = .... deriving( Monad )</span><span>
</span><span id="line-846"></span><span>                </span><span class="hs-comment">--  (b) The args to drop are all *distinct* type variables; eg reject:</span><span>
</span><span id="line-847"></span><span>                </span><span class="hs-comment">--              class C (a :: * -&gt; * -&gt; *) where ...</span><span>
</span><span id="line-848"></span><span>                </span><span class="hs-comment">--              data instance T a a = ... deriving( C )</span><span>
</span><span id="line-849"></span><span>                </span><span class="hs-comment">--  (c) The type class args, or remaining tycon args,</span><span>
</span><span id="line-850"></span><span>                </span><span class="hs-comment">--      do not mention any of the dropped type variables</span><span>
</span><span id="line-851"></span><span>                </span><span class="hs-comment">--              newtype T a s = ... deriving( ST s )</span><span>
</span><span id="line-852"></span><span>                </span><span class="hs-comment">--              newtype instance K a a = ... deriving( Monad )</span><span>
</span><span id="line-853"></span><span>                </span><span class="hs-comment">--</span><span>
</span><span id="line-854"></span><span>                </span><span class="hs-comment">-- It is vital that the implementation of allDistinctTyVars</span><span>
</span><span id="line-855"></span><span>                </span><span class="hs-comment">-- expand any type synonyms.</span><span>
</span><span id="line-856"></span><span>                </span><span class="hs-comment">-- See Note [Eta-reducing type synonyms]</span><span>
</span><span id="line-857"></span><span>
</span><span id="line-858"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">UserTypeCtxt -&gt; Class -&gt; [PredType] -&gt; TcRn ()
</span><a href="GHC.Tc.Validity.html#checkValidInstHead"><span class="hs-identifier hs-var">checkValidInstHead</span></a></span><span> </span><span class="annot"><span class="annottext">UserTypeCtxt
</span><a href="GHC.Tc.Types.Origin.html#DerivClauseCtxt"><span class="hs-identifier hs-var">DerivClauseCtxt</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168677"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168615"><span class="hs-identifier hs-var">final_cls_args</span></a></span><span>
</span><span id="line-859"></span><span>                </span><span class="hs-comment">-- Check that we aren't deriving an instance of a magical</span><span>
</span><span id="line-860"></span><span>                </span><span class="hs-comment">-- type like (~) or Coercible (#14916).</span><span>
</span><span id="line-861"></span><span>
</span><span id="line-862"></span><span>        </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168611"><span class="annot"><span class="annottext">EarlyDerivSpec
</span><a href="#local-6989586621681168611"><span class="hs-identifier hs-var">spec</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe OverlapMode
-&gt; [TyVar]
-&gt; Class
-&gt; [PredType]
-&gt; DerivContext
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mkEqnHelp"><span class="hs-identifier hs-var">mkEqnHelp</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe OverlapMode
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168626"><span class="hs-identifier hs-var">final_tkvs</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168677"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168615"><span class="hs-identifier hs-var">final_cls_args</span></a></span><span>
</span><span id="line-863"></span><span>                            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe SrcSpan -&gt; DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#InferContext"><span class="hs-identifier hs-var">InferContext</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe SrcSpan
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168623"><span class="hs-identifier hs-var">final_mb_deriv_strat</span></a></span><span>
</span><span id="line-864"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;deriveTyData 3&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EarlyDerivSpec -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">EarlyDerivSpec
</span><a href="#local-6989586621681168611"><span class="hs-identifier hs-var">spec</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-865"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">EarlyDerivSpec -&gt; IOEnv (Env TcGblEnv TcLclEnv) EarlyDerivSpec
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">EarlyDerivSpec
</span><a href="#local-6989586621681168611"><span class="hs-identifier hs-var">spec</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-866"></span><span>
</span><span id="line-867"></span><span>
</span><span id="line-868"></span><span class="hs-comment">{- Note [tc_args and tycon arity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You might wonder if we could use (tyConArity tc) at this point, rather
than (length tc_args).  But for data families the two can differ!  The
tc and tc_args passed into 'deriveTyData' come from 'deriveClause' which
in turn gets them from 'tyConFamInstSig_maybe' which in turn gets them
from DataFamInstTyCon:

| DataFamInstTyCon          -- See Note [Data type families]
      (CoAxiom Unbranched)
      TyCon   -- The family TyCon
      [Type]  -- Argument types (mentions the tyConTyVars of this TyCon)
              -- No shorter in length than the tyConTyVars of the family TyCon
              -- How could it be longer? See [Arity of data families] in GHC.Core.FamInstEnv

Notice that the arg tys might not be the same as the family tycon arity
(= length tyConTyVars).

Note [Unify kinds in deriving]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider (#8534)
    data T a b = MkT a deriving( Functor )
    -- where Functor :: (*-&gt;*) -&gt; Constraint

So T :: forall k. * -&gt; k -&gt; *.   We want to get
    instance Functor (T * (a:*)) where ...
Notice the '*' argument to T.

Moreover, as well as instantiating T's kind arguments, we may need to instantiate
C's kind args.  Consider (#8865):
  newtype T a b = MkT (Either a b) deriving( Category )
where
  Category :: forall k. (k -&gt; k -&gt; *) -&gt; Constraint
We need to generate the instance
  instance Category * (Either a) where ...
Notice the '*' argument to Category.

So we need to
 * drop arguments from (T a b) to match the number of
   arrows in the (last argument of the) class;
 * and then *unify* kind of the remaining type against the
   expected kind, to figure out how to instantiate C's and T's
   kind arguments.

In the two examples,
 * we unify   kind-of( T k (a:k) ) ~ kind-of( Functor )
         i.e.      (k -&gt; *) ~ (* -&gt; *)   to find k:=*.
         yielding  k:=*

 * we unify   kind-of( Either ) ~ kind-of( Category )
         i.e.      (* -&gt; * -&gt; *)  ~ (k -&gt; k -&gt; k)
         yielding  k:=*

Now we get a kind substitution.  We then need to:

  1. Remove the substituted-out kind variables from the quantified kind vars

  2. Apply the substitution to the kinds of quantified *type* vars
     (and extend the substitution to reflect this change)

  3. Apply that extended substitution to the non-dropped args (types and
     kinds) of the type and class

Forgetting step (2) caused #8893:
  data V a = V [a] deriving Functor
  data P (x::k-&gt;*) (a:k) = P (x a) deriving Functor
  data C (x::k-&gt;*) (a:k) = C (V (P x a)) deriving Functor

When deriving Functor for P, we unify k to *, but we then want
an instance   $df :: forall (x:*-&gt;*). Functor x =&gt; Functor (P * (x:*-&gt;*))
and similarly for C.  Notice the modified kind of x, both at binding
and occurrence sites.

This can lead to some surprising results when *visible* kind binder is
unified (in contrast to the above examples, in which only non-visible kind
binders were considered). Consider this example from #11732:

    data T k (a :: k) = MkT deriving Functor

Since unification yields k:=*, this results in a generated instance of:

    instance Functor (T *) where ...

which looks odd at first glance, since one might expect the instance head
to be of the form Functor (T k). Indeed, one could envision an alternative
generated instance of:

    instance (k ~ *) =&gt; Functor (T k) where

But this does not typecheck by design: kind equalities are not allowed to be
bound in types, only terms. But in essence, the two instance declarations are
entirely equivalent, since even though (T k) matches any kind k, the only
possibly value for k is *, since anything else is ill-typed. As a result, we can
just as comfortably use (T *).

Another way of thinking about is: deriving clauses often infer constraints.
For example:

    data S a = S a deriving Eq

infers an (Eq a) constraint in the derived instance. By analogy, when we
are deriving Functor, we might infer an equality constraint (e.g., k ~ *).
The only distinction is that GHC instantiates equality constraints directly
during the deriving process.

Another quirk of this design choice manifests when typeclasses have visible
kind parameters. Consider this code (also from #11732):

    class Cat k (cat :: k -&gt; k -&gt; *) where
      catId   :: cat a a
      catComp :: cat b c -&gt; cat a b -&gt; cat a c

    instance Cat * (-&gt;) where
      catId   = id
      catComp = (.)

    newtype Fun a b = Fun (a -&gt; b) deriving (Cat k)

Even though we requested a derived instance of the form (Cat k Fun), the
kind unification will actually generate (Cat * Fun) (i.e., the same thing as if
the user wrote deriving (Cat *)).

What happens with DerivingVia, when you have yet another type? Consider:

  newtype Foo (a :: Type) = MkFoo (Proxy a)
    deriving Functor via Proxy

As before, we unify the kind of Foo (* -&gt; *) with the kind of the argument to
Functor (* -&gt; *). But that's not enough: the `via` type, Proxy, has the kind
(k -&gt; *), which is more general than what we want. So we must additionally
unify (k -&gt; *) with (* -&gt; *).

Currently, all of this unification is implemented kludgily with the pure
unifier, which is rather tiresome. #14331 lays out a plan for how this
might be made cleaner.

Note [Unification of two kind variables in deriving]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As a special case of the Note above, it is possible to derive an instance of
a poly-kinded typeclass for a poly-kinded datatype. For example:

    class Category (cat :: k -&gt; k -&gt; *) where
    newtype T (c :: k -&gt; k -&gt; *) a b = MkT (c a b) deriving Category

This case is surprisingly tricky. To see why, let's write out what instance GHC
will attempt to derive (using -fprint-explicit-kinds syntax):

    instance Category k1 (T k2 c) where ...

GHC will attempt to unify k1 and k2, which produces a substitution (kind_subst)
that looks like [k2 :-&gt; k1]. Importantly, we need to apply this substitution to
the type variable binder for c, since its kind is (k2 -&gt; k2 -&gt; *).

We used to accomplish this by doing the following:

    unmapped_tkvs = filter (`notElemTCvSubst` kind_subst) all_tkvs
    (subst, _)    = substTyVarBndrs kind_subst unmapped_tkvs

Where all_tkvs contains all kind variables in the class and instance types (in
this case, all_tkvs = [k1,k2]). But since kind_subst only has one mapping,
this results in unmapped_tkvs being [k1], and as a consequence, k1 gets mapped
to another kind variable in subst! That is, subst = [k2 :-&gt; k1, k1 :-&gt; k_new].
This is bad, because applying that substitution yields the following instance:

   instance Category k_new (T k1 c) where ...

In other words, keeping k1 in unmapped_tvks taints the substitution, resulting
in an ill-kinded instance (this caused #11837).

To prevent this, we need to filter out any variable from all_tkvs which either

1. Appears in the domain of kind_subst. notElemTCvSubst checks this.
2. Appears in the range of kind_subst. To do this, we compute the free
   variable set of the range of kind_subst with getTCvSubstRangeFVs, and check
   if a kind variable appears in that set.

Note [Eta-reducing type synonyms]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
One can instantiate a type in a data family instance with a type synonym that
mentions other type variables:

  type Const a b = a
  data family Fam (f :: * -&gt; *) (a :: *)
  newtype instance Fam f (Const a f) = Fam (f a) deriving Functor

It is also possible to define kind synonyms, and they can mention other types in
a datatype declaration. For example,

  type Const a b = a
  newtype T f (a :: Const * f) = T (f a) deriving Functor

When deriving, we need to perform eta-reduction analysis to ensure that none of
the eta-reduced type variables are mentioned elsewhere in the declaration. But
we need to be careful, because if we don't expand through the Const type
synonym, we will mistakenly believe that f is an eta-reduced type variable and
fail to derive Functor, even though the code above is correct (see #11416,
where this was first noticed). For this reason, we expand the type synonyms in
the eta-reduced types before doing any analysis.

Note [Floating `via` type variables]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When generating a derived instance, it will be of the form:

  instance forall ???. C c_args (D d_args) where ...

To fill in ???, GHC computes the free variables of `c_args` and `d_args`.
`DerivingVia` adds an extra wrinkle to this formula, since we must also
include the variables bound by the `via` type when computing the binders
used to fill in ???. This might seem strange, since if a `via` type binds
any type variables, then in almost all scenarios it will appear free in
`c_args` or `d_args`. There are certain corner cases where this does not hold,
however, such as in the following example (adapted from #15831):

  newtype Age = MkAge Int
    deriving Eq via Const Int a

In this example, the `via` type binds the type variable `a`, but `a` appears
nowhere in `Eq Age`. Nevertheless, we include it in the generated instance:

  instance forall a. Eq Age where
    (==) = coerce @(Const Int a -&gt; Const Int a -&gt; Bool)
                  @(Age         -&gt; Age         -&gt; Bool)
                  (==)

The use of `forall a` is certainly required here, since the `a` in
`Const Int a` would not be in scope otherwise. This instance is somewhat
strange in that nothing in the instance head `Eq Age` ever determines what `a`
will be, so any code that uses this instance will invariably instantiate `a`
to be `Any`. We refer to this property of `a` as being a &quot;floating&quot; `via`
type variable. Programs with floating `via` type variables are the only known
class of program in which the `via` type quantifies type variables that aren't
mentioned in the instance head in the generated instance.

Fortunately, the choice to instantiate floating `via` type variables to `Any`
is one that is completely transparent to the user (since the instance will
work as expected regardless of what `a` is instantiated to), so we decide to
permit them. An alternative design would make programs with floating `via`
variables illegal, by requiring that every variable mentioned in the `via` type
is also mentioned in the data header or the derived class. That restriction
would require the user to pick a particular type (the choice does not matter);
for example:

  newtype Age = MkAge Int
    -- deriving Eq via Const Int a  -- Floating 'a'
    deriving Eq via Const Int ()    -- Choose a=()
    deriving Eq via Const Int Any   -- Choose a=Any

No expressiveness would be lost thereby, but stylistically it seems preferable
to allow a type variable to indicate &quot;it doesn't matter&quot;.

Note that by quantifying the `a` in `forall a. Eq Age`, we are deferring the
work of instantiating `a` to `Any` at every use site of the instance. An
alternative approach would be to generate an instance that directly defaulted
to `Any`:

  instance Eq Age where
    (==) = coerce @(Const Int Any -&gt; Const Int Any -&gt; Bool)
                  @(Age           -&gt; Age           -&gt; Bool)
                  (==)

We do not implement this approach since it would require a nontrivial amount
of implementation effort to substitute `Any` for the floating `via` type
variables, and since the end result isn't distinguishable from the former
instance (at least from the user's perspective), the amount of engineering
required to obtain the latter instance just isn't worth it.
-}</span><span>
</span><span id="line-1134"></span><span>
</span><span id="line-1135"></span><span class="annot"><a href="GHC.Tc.Deriv.html#mkEqnHelp"><span class="hs-identifier hs-type">mkEqnHelp</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#OverlapMode"><span class="hs-identifier hs-type">OverlapMode</span></a></span><span>
</span><span id="line-1136"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1137"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1138"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivContext"><span class="hs-identifier hs-type">DerivContext</span></a></span><span>
</span><span id="line-1139"></span><span>               </span><span class="hs-comment">-- SupplyContext =&gt; context supplied (standalone deriving)</span><span>
</span><span id="line-1140"></span><span>               </span><span class="hs-comment">-- InferContext  =&gt; context inferred (deriving on data decl, or</span><span>
</span><span id="line-1141"></span><span>               </span><span class="hs-comment">--                  standalone deriving decl with a wildcard)</span><span>
</span><span id="line-1142"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#DerivStrategy"><span class="hs-identifier hs-type">DerivStrategy</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1143"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcRn"><span class="hs-identifier hs-type">TcRn</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1144"></span><span class="hs-comment">-- Make the EarlyDerivSpec for an instance</span><span>
</span><span id="line-1145"></span><span class="hs-comment">--      forall tvs. theta =&gt; cls (tys ++ [ty])</span><span>
</span><span id="line-1146"></span><span class="hs-comment">-- where the 'theta' is optional (that's the Maybe part)</span><span>
</span><span id="line-1147"></span><span class="hs-comment">-- Assumes that this declaration is well-kinded</span><span>
</span><span id="line-1148"></span><span>
</span><span id="line-1149"></span><span id="mkEqnHelp"><span class="annot"><span class="annottext">mkEqnHelp :: Maybe OverlapMode
-&gt; [TyVar]
-&gt; Class
-&gt; [PredType]
-&gt; DerivContext
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mkEqnHelp"><span class="hs-identifier hs-var hs-var">mkEqnHelp</span></a></span></span><span> </span><span id="local-6989586621681168610"><span class="annot"><span class="annottext">Maybe OverlapMode
</span><a href="#local-6989586621681168610"><span class="hs-identifier hs-var">overlap_mode</span></a></span></span><span> </span><span id="local-6989586621681168609"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168609"><span class="hs-identifier hs-var">tvs</span></a></span></span><span> </span><span id="local-6989586621681168608"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168608"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621681168607"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168607"><span class="hs-identifier hs-var">cls_args</span></a></span></span><span> </span><span id="local-6989586621681168606"><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168606"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span></span><span> </span><span id="local-6989586621681168605"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168605"><span class="hs-identifier hs-var">deriv_strat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1150"></span><span>  </span><span id="local-6989586621681168604"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168604"><span class="hs-identifier hs-var">is_boot</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRnIf TcGblEnv TcLclEnv Bool
</span><a href="GHC.Tc.Utils.Monad.html#tcIsHsBootOrSig"><span class="hs-identifier hs-var">tcIsHsBootOrSig</span></a></span><span>
</span><span id="line-1151"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; TcRn () -&gt; TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168604"><span class="hs-identifier hs-var">is_boot</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; TcRn ()) -&gt; TcRn () -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1152"></span><span>       </span><span class="annot"><span class="annottext">SDoc -&gt; TcRn ()
</span><a href="#local-6989586621681168602"><span class="hs-identifier hs-var">bale_out</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Cannot derive instances in hs-boot files&quot;</span></span><span>
</span><span id="line-1153"></span><span>             </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%2B%24"><span class="hs-operator hs-var">$+$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Write an instance declaration instead&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-1154"></span><span>  </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn EarlyDerivSpec
-&gt; DerivEnv -&gt; IOEnv (Env TcGblEnv TcLclEnv) EarlyDerivSpec
forall r (m :: * -&gt; *) a. ReaderT r m a -&gt; r -&gt; m a
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#runReaderT"><span class="hs-identifier hs-var hs-var">runReaderT</span></a></span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168599"><span class="hs-identifier hs-var">mk_eqn</span></a></span><span> </span><span class="annot"><span class="annottext">DerivEnv
</span><a href="#local-6989586621681168598"><span class="hs-identifier hs-var">deriv_env</span></a></span><span>
</span><span id="line-1155"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1156"></span><span>    </span><span id="local-6989586621681168598"><span class="annot"><span class="annottext">deriv_env :: DerivEnv
</span><a href="#local-6989586621681168598"><span class="hs-identifier hs-var hs-var">deriv_env</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivEnv :: Maybe OverlapMode
-&gt; [TyVar]
-&gt; Class
-&gt; [PredType]
-&gt; DerivContext
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; DerivEnv
</span><a href="GHC.Tc.Deriv.Utils.html#DerivEnv"><span class="hs-identifier hs-type">DerivEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">denv_overlap_mode :: Maybe OverlapMode
</span><a href="GHC.Tc.Deriv.Utils.html#denv_overlap_mode"><span class="hs-identifier hs-var">denv_overlap_mode</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe OverlapMode
</span><a href="#local-6989586621681168610"><span class="hs-identifier hs-var">overlap_mode</span></a></span><span>
</span><span id="line-1157"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_tvs :: [TyVar]
</span><a href="GHC.Tc.Deriv.Utils.html#denv_tvs"><span class="hs-identifier hs-var">denv_tvs</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168609"><span class="hs-identifier hs-var">tvs</span></a></span><span>
</span><span id="line-1158"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_cls :: Class
</span><a href="GHC.Tc.Deriv.Utils.html#denv_cls"><span class="hs-identifier hs-var">denv_cls</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168608"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-1159"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_inst_tys :: [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#denv_inst_tys"><span class="hs-identifier hs-var">denv_inst_tys</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168607"><span class="hs-identifier hs-var">cls_args</span></a></span><span>
</span><span id="line-1160"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_ctxt :: DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#denv_ctxt"><span class="hs-identifier hs-var">denv_ctxt</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168606"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span><span>
</span><span id="line-1161"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_strat :: Maybe (DerivStrategy GhcTc)
</span><a href="GHC.Tc.Deriv.Utils.html#denv_strat"><span class="hs-identifier hs-var">denv_strat</span></a></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168605"><span class="hs-identifier hs-var">deriv_strat</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1162"></span><span>
</span><span id="line-1163"></span><span>    </span><span id="local-6989586621681168602"><span class="annot"><span class="annottext">bale_out :: SDoc -&gt; TcRn ()
</span><a href="#local-6989586621681168602"><span class="hs-identifier hs-var hs-var">bale_out</span></a></span></span><span> </span><span id="local-6989586621681168590"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168590"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; TcRn ()
forall a. SDoc -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#failWithTc"><span class="hs-identifier hs-var">failWithTc</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcRn ()) -&gt; SDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
-&gt; Class
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; SDoc
-&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErr"><span class="hs-identifier hs-var">derivingThingErr</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168608"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168607"><span class="hs-identifier hs-var">cls_args</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168605"><span class="hs-identifier hs-var">deriv_strat</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168590"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-1164"></span><span>
</span><span id="line-1165"></span><span>    </span><span class="annot"><a href="#local-6989586621681168599"><span class="hs-identifier hs-type">mk_eqn</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1166"></span><span>    </span><span id="local-6989586621681168599"><span class="annot"><span class="annottext">mk_eqn :: ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168599"><span class="hs-identifier hs-var hs-var">mk_eqn</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1167"></span><span>      </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivEnv"><span class="hs-identifier hs-type">DerivEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">denv_inst_tys :: DerivEnv -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#denv_inst_tys"><span class="hs-identifier hs-var">denv_inst_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168588"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168588"><span class="hs-identifier hs-var">cls_args</span></a></span></span><span>
</span><span id="line-1168"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_strat :: DerivEnv -&gt; Maybe (DerivStrategy GhcTc)
</span><a href="GHC.Tc.Deriv.Utils.html#denv_strat"><span class="hs-identifier hs-var">denv_strat</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168587"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168587"><span class="hs-identifier hs-var">mb_strat</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DerivEnv
forall (m :: * -&gt; *) r. Monad m =&gt; ReaderT r m r
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#ask"><span class="hs-identifier hs-var">ask</span></a></span><span>
</span><span id="line-1169"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168587"><span class="hs-identifier hs-var">mb_strat</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1170"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">DerivStrategy GhcTc
</span><a href="GHC.Hs.Decls.html#StockStrategy"><span class="hs-identifier hs-var">StockStrategy</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1171"></span><span>          </span><span class="hs-special">(</span><span id="local-6989586621681168584"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168584"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168583"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168583"><span class="hs-identifier hs-var">inst_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; DerivM ([PredType], PredType)
</span><a href="GHC.Tc.Deriv.html#expectNonNullaryClsArgs"><span class="hs-identifier hs-var">expectNonNullaryClsArgs</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168588"><span class="hs-identifier hs-var">cls_args</span></a></span><span>
</span><span id="line-1172"></span><span>          </span><span id="local-6989586621681168581"><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168581"><span class="hs-identifier hs-var">dit</span></a></span></span><span>                </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; PredType -&gt; DerivM DerivInstTys
</span><a href="GHC.Tc.Deriv.html#expectAlgTyConApp"><span class="hs-identifier hs-var">expectAlgTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168584"><span class="hs-identifier hs-var">cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168583"><span class="hs-identifier hs-var">inst_ty</span></a></span><span>
</span><span id="line-1173"></span><span>          </span><span class="annot"><span class="annottext">DerivInstTys -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_stock"><span class="hs-identifier hs-var">mk_eqn_stock</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168581"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1174"></span><span>
</span><span id="line-1175"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">DerivStrategy GhcTc
</span><a href="GHC.Hs.Decls.html#AnyclassStrategy"><span class="hs-identifier hs-var">AnyclassStrategy</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_anyclass"><span class="hs-identifier hs-var">mk_eqn_anyclass</span></a></span><span>
</span><span id="line-1176"></span><span>
</span><span id="line-1177"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#ViaStrategy"><span class="hs-identifier hs-type">ViaStrategy</span></a></span><span> </span><span id="local-6989586621681168576"><span class="annot"><span class="annottext">XViaStrategy GhcTc
</span><a href="#local-6989586621681168576"><span class="hs-identifier hs-var">via_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1178"></span><span>          </span><span class="hs-special">(</span><span id="local-6989586621681168575"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168575"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168574"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168574"><span class="hs-identifier hs-var">inst_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; DerivM ([PredType], PredType)
</span><a href="GHC.Tc.Deriv.html#expectNonNullaryClsArgs"><span class="hs-identifier hs-var">expectNonNullaryClsArgs</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168588"><span class="hs-identifier hs-var">cls_args</span></a></span><span>
</span><span id="line-1179"></span><span>          </span><span class="annot"><span class="annottext">[PredType]
-&gt; PredType -&gt; PredType -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_via"><span class="hs-identifier hs-var">mk_eqn_via</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168575"><span class="hs-identifier hs-var">cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168574"><span class="hs-identifier hs-var">inst_ty</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
XViaStrategy GhcTc
</span><a href="#local-6989586621681168576"><span class="hs-identifier hs-var">via_ty</span></a></span><span>
</span><span id="line-1180"></span><span>
</span><span id="line-1181"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">DerivStrategy GhcTc
</span><a href="GHC.Hs.Decls.html#NewtypeStrategy"><span class="hs-identifier hs-var">NewtypeStrategy</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1182"></span><span>          </span><span class="hs-special">(</span><span id="local-6989586621681168571"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168571"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168570"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168570"><span class="hs-identifier hs-var">inst_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; DerivM ([PredType], PredType)
</span><a href="GHC.Tc.Deriv.html#expectNonNullaryClsArgs"><span class="hs-identifier hs-var">expectNonNullaryClsArgs</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168588"><span class="hs-identifier hs-var">cls_args</span></a></span><span>
</span><span id="line-1183"></span><span>          </span><span id="local-6989586621681168569"><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168569"><span class="hs-identifier hs-var">dit</span></a></span></span><span>                </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; PredType -&gt; DerivM DerivInstTys
</span><a href="GHC.Tc.Deriv.html#expectAlgTyConApp"><span class="hs-identifier hs-var">expectAlgTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168571"><span class="hs-identifier hs-var">cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168570"><span class="hs-identifier hs-var">inst_ty</span></a></span><span>
</span><span id="line-1184"></span><span>          </span><span class="annot"><span class="annottext">Bool -&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Bool
</span><a href="GHC.Core.TyCon.html#isNewTyCon"><span class="hs-identifier hs-var">isNewTyCon</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc"><span class="hs-identifier hs-var hs-var">dit_rep_tc</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168569"><span class="hs-identifier hs-var">dit</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1185"></span><span>            </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; ReaderT DerivEnv TcRn ()
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Tc.Deriv.html#gndNonNewtypeErr"><span class="hs-identifier hs-var">gndNonNewtypeErr</span></a></span><span>
</span><span id="line-1186"></span><span>          </span><span class="annot"><span class="annottext">Bool -&gt; DerivInstTys -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mkNewTypeEqn"><span class="hs-identifier hs-var">mkNewTypeEqn</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168569"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1187"></span><span>
</span><span id="line-1188"></span><span>        </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_no_strategy"><span class="hs-identifier hs-var">mk_eqn_no_strategy</span></a></span><span>
</span><span id="line-1189"></span><span>
</span><span id="line-1190"></span><span class="hs-comment">-- @expectNonNullaryClsArgs inst_tys@ checks if @inst_tys@ is non-empty.</span><span>
</span><span id="line-1191"></span><span class="hs-comment">-- If so, return @(init inst_tys, last inst_tys)@.</span><span>
</span><span id="line-1192"></span><span class="hs-comment">-- Otherwise, throw an error message.</span><span>
</span><span id="line-1193"></span><span class="hs-comment">-- See @Note [DerivEnv and DerivSpecMechanism]@ in &quot;GHC.Tc.Deriv.Utils&quot; for why this</span><span>
</span><span id="line-1194"></span><span class="hs-comment">-- property is important.</span><span>
</span><span id="line-1195"></span><span class="annot"><a href="GHC.Tc.Deriv.html#expectNonNullaryClsArgs"><span class="hs-identifier hs-type">expectNonNullaryClsArgs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1196"></span><span id="expectNonNullaryClsArgs"><span class="annot"><span class="annottext">expectNonNullaryClsArgs :: [PredType] -&gt; DerivM ([PredType], PredType)
</span><a href="GHC.Tc.Deriv.html#expectNonNullaryClsArgs"><span class="hs-identifier hs-var hs-var">expectNonNullaryClsArgs</span></a></span></span><span> </span><span id="local-6989586621681168562"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168562"><span class="hs-identifier hs-var">inst_tys</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1197"></span><span>  </span><span class="annot"><span class="annottext">DerivM ([PredType], PredType)
-&gt; (([PredType], PredType) -&gt; DerivM ([PredType], PredType))
-&gt; Maybe ([PredType], PredType)
-&gt; DerivM ([PredType], PredType)
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><a href="../../base/src/Data.Maybe.html#maybe"><span class="hs-identifier hs-var">maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; DerivM ([PredType], PredType)
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Tc.Deriv.html#derivingNullaryErr"><span class="hs-identifier hs-var">derivingNullaryErr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([PredType], PredType) -&gt; DerivM ([PredType], PredType)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">(Maybe ([PredType], PredType) -&gt; DerivM ([PredType], PredType))
-&gt; Maybe ([PredType], PredType) -&gt; DerivM ([PredType], PredType)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1198"></span><span>  </span><span class="annot"><span class="annottext">[PredType] -&gt; Maybe ([PredType], PredType)
forall a. [a] -&gt; Maybe ([a], a)
</span><a href="GHC.Utils.Misc.html#snocView"><span class="hs-identifier hs-var">snocView</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168562"><span class="hs-identifier hs-var">inst_tys</span></a></span><span>
</span><span id="line-1199"></span><span>
</span><span id="line-1200"></span><span class="hs-comment">-- @expectAlgTyConApp cls_tys inst_ty@ checks if @inst_ty@ is an application</span><span>
</span><span id="line-1201"></span><span class="hs-comment">-- of an algebraic type constructor. If so, return a 'DerivInstTys' consisting</span><span>
</span><span id="line-1202"></span><span class="hs-comment">-- of @cls_tys@ and the constituent pars of @inst_ty@.</span><span>
</span><span id="line-1203"></span><span class="hs-comment">-- Otherwise, throw an error message.</span><span>
</span><span id="line-1204"></span><span class="hs-comment">-- See @Note [DerivEnv and DerivSpecMechanism]@ in &quot;GHC.Tc.Deriv.Utils&quot; for why this</span><span>
</span><span id="line-1205"></span><span class="hs-comment">-- property is important.</span><span>
</span><span id="line-1206"></span><span class="annot"><a href="GHC.Tc.Deriv.html#expectAlgTyConApp"><span class="hs-identifier hs-type">expectAlgTyConApp</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- All but the last argument to the class in a</span><span>
</span><span id="line-1207"></span><span>                            </span><span class="hs-comment">-- derived instance</span><span>
</span><span id="line-1208"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>   </span><span class="hs-comment">-- The last argument to the class in a</span><span>
</span><span id="line-1209"></span><span>                            </span><span class="hs-comment">-- derived instance</span><span>
</span><span id="line-1210"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span>
</span><span id="line-1211"></span><span id="expectAlgTyConApp"><span class="annot"><span class="annottext">expectAlgTyConApp :: [PredType] -&gt; PredType -&gt; DerivM DerivInstTys
</span><a href="GHC.Tc.Deriv.html#expectAlgTyConApp"><span class="hs-identifier hs-var hs-var">expectAlgTyConApp</span></a></span></span><span> </span><span id="local-6989586621681168558"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168558"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span> </span><span id="local-6989586621681168557"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168557"><span class="hs-identifier hs-var">inst_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1212"></span><span>  </span><span id="local-6989586621681168556"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621681168556"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) FamInstEnvs
-&gt; ReaderT DerivEnv TcRn FamInstEnvs
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) FamInstEnvs
</span><a href="GHC.Tc.Instance.Family.html#tcGetFamInstEnvs"><span class="hs-identifier hs-var">tcGetFamInstEnvs</span></a></span><span>
</span><span id="line-1213"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">FamInstEnvs -&gt; [PredType] -&gt; PredType -&gt; Maybe DerivInstTys
</span><a href="GHC.Tc.Deriv.html#mk_deriv_inst_tys_maybe"><span class="hs-identifier hs-var">mk_deriv_inst_tys_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621681168556"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168558"><span class="hs-identifier hs-var">cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168557"><span class="hs-identifier hs-var">inst_ty</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1214"></span><span>    </span><span class="annot"><span class="annottext">Maybe DerivInstTys
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; DerivM DerivInstTys
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; DerivM DerivInstTys) -&gt; SDoc -&gt; DerivM DerivInstTys
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1215"></span><span>                   </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;The last argument of the instance must be a&quot;</span></span><span>
</span><span id="line-1216"></span><span>               </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;data or newtype application&quot;</span></span><span>
</span><span id="line-1217"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681168552"><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168552"><span class="hs-identifier hs-var">dit</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">DerivInstTys -&gt; ReaderT DerivEnv TcRn ()
</span><a href="GHC.Tc.Deriv.html#expectNonDataFamTyCon"><span class="hs-identifier hs-var">expectNonDataFamTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168552"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1218"></span><span>                   </span><span class="annot"><span class="annottext">DerivInstTys -&gt; DerivM DerivInstTys
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168552"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1219"></span><span>
</span><span id="line-1220"></span><span class="hs-comment">-- @expectNonDataFamTyCon dit@ checks if @dit_rep_tc dit@ is a representation</span><span>
</span><span id="line-1221"></span><span class="hs-comment">-- type constructor for a data family instance, and if not,</span><span>
</span><span id="line-1222"></span><span class="hs-comment">-- throws an error message.</span><span>
</span><span id="line-1223"></span><span class="hs-comment">-- See @Note [DerivEnv and DerivSpecMechanism]@ in &quot;GHC.Tc.Deriv.Utils&quot; for why this</span><span>
</span><span id="line-1224"></span><span class="hs-comment">-- property is important.</span><span>
</span><span id="line-1225"></span><span class="annot"><a href="GHC.Tc.Deriv.html#expectNonDataFamTyCon"><span class="hs-identifier hs-type">expectNonDataFamTyCon</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1226"></span><span id="expectNonDataFamTyCon"><span class="annot"><span class="annottext">expectNonDataFamTyCon :: DerivInstTys -&gt; ReaderT DerivEnv TcRn ()
</span><a href="GHC.Tc.Deriv.html#expectNonDataFamTyCon"><span class="hs-identifier hs-var hs-var">expectNonDataFamTyCon</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dit_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_tc"><span class="hs-identifier hs-var">dit_tc</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168548"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168548"><span class="hs-identifier hs-var">tc</span></a></span></span><span>
</span><span id="line-1227"></span><span>                                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_tc_args :: DerivInstTys -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#dit_tc_args"><span class="hs-identifier hs-var">dit_tc_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168546"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168546"><span class="hs-identifier hs-var">tc_args</span></a></span></span><span>
</span><span id="line-1228"></span><span>                                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_rep_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc"><span class="hs-identifier hs-var">dit_rep_tc</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168545"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168545"><span class="hs-identifier hs-var">rep_tc</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1229"></span><span>  </span><span class="hs-comment">-- If it's still a data family, the lookup failed; i.e no instance exists</span><span>
</span><span id="line-1230"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Bool
</span><a href="GHC.Core.TyCon.html#isDataFamilyTyCon"><span class="hs-identifier hs-var">isDataFamilyTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168545"><span class="hs-identifier hs-var">rep_tc</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1231"></span><span>    </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; ReaderT DerivEnv TcRn ()
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; ReaderT DerivEnv TcRn ())
-&gt; SDoc -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1232"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;No family instance for&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [PredType] -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprTypeApp"><span class="hs-identifier hs-var">pprTypeApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168548"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168546"><span class="hs-identifier hs-var">tc_args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1233"></span><span>
</span><span id="line-1234"></span><span class="annot"><a href="GHC.Tc.Deriv.html#mk_deriv_inst_tys_maybe"><span class="hs-identifier hs-type">mk_deriv_inst_tys_maybe</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span>
</span><span id="line-1235"></span><span>                        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span>
</span><span id="line-1236"></span><span id="mk_deriv_inst_tys_maybe"><span class="annot"><span class="annottext">mk_deriv_inst_tys_maybe :: FamInstEnvs -&gt; [PredType] -&gt; PredType -&gt; Maybe DerivInstTys
</span><a href="GHC.Tc.Deriv.html#mk_deriv_inst_tys_maybe"><span class="hs-identifier hs-var hs-var">mk_deriv_inst_tys_maybe</span></a></span></span><span> </span><span id="local-6989586621681168542"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621681168542"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span id="local-6989586621681168541"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168541"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span> </span><span id="local-6989586621681168540"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168540"><span class="hs-identifier hs-var">inst_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1237"></span><span>  </span><span class="annot"><span class="annottext">((TyCon, [PredType]) -&gt; DerivInstTys)
-&gt; Maybe (TyCon, [PredType]) -&gt; Maybe DerivInstTys
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">(TyCon, [PredType]) -&gt; DerivInstTys
</span><a href="#local-6989586621681168539"><span class="hs-identifier hs-var">lookup</span></a></span><span> </span><span class="annot"><span class="annottext">(Maybe (TyCon, [PredType]) -&gt; Maybe DerivInstTys)
-&gt; Maybe (TyCon, [PredType]) -&gt; Maybe DerivInstTys
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; PredType -&gt; Maybe (TyCon, [PredType])
PredType -&gt; Maybe (TyCon, [PredType])
</span><a href="GHC.Core.Type.html#tcSplitTyConApp_maybe"><span class="hs-identifier hs-var">tcSplitTyConApp_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168540"><span class="hs-identifier hs-var">inst_ty</span></a></span><span>
</span><span id="line-1238"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1239"></span><span>    </span><span class="annot"><a href="#local-6989586621681168539"><span class="hs-identifier hs-type">lookup</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span>
</span><span id="line-1240"></span><span>    </span><span id="local-6989586621681168539"><span class="annot"><span class="annottext">lookup :: (TyCon, [PredType]) -&gt; DerivInstTys
</span><a href="#local-6989586621681168539"><span class="hs-identifier hs-var hs-var">lookup</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168537"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168537"><span class="hs-identifier hs-var">tc</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168536"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168536"><span class="hs-identifier hs-var">tc_args</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1241"></span><span>      </span><span class="hs-comment">-- Find the instance of a data family</span><span>
</span><span id="line-1242"></span><span>      </span><span class="hs-comment">-- Note [Looking up family instances for deriving]</span><span>
</span><span id="line-1243"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168535"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168535"><span class="hs-identifier hs-var">rep_tc</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168534"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168534"><span class="hs-identifier hs-var">rep_tc_args</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168533"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621681168533"><span class="hs-identifier hs-var">_co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInstEnvs -&gt; TyCon -&gt; [PredType] -&gt; (TyCon, [PredType], Coercion)
</span><a href="GHC.Tc.Instance.Family.html#tcLookupDataFamInst"><span class="hs-identifier hs-var">tcLookupDataFamInst</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621681168542"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168537"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168536"><span class="hs-identifier hs-var">tc_args</span></a></span><span>
</span><span id="line-1244"></span><span>      </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">DerivInstTys :: [PredType]
-&gt; TyCon -&gt; [PredType] -&gt; TyCon -&gt; [PredType] -&gt; DerivInstTys
</span><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dit_cls_tys :: [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#dit_cls_tys"><span class="hs-identifier hs-var">dit_cls_tys</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168541"><span class="hs-identifier hs-var">cls_tys</span></a></span><span>
</span><span id="line-1245"></span><span>                      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_tc :: TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_tc"><span class="hs-identifier hs-var">dit_tc</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168537"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-1246"></span><span>                      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_tc_args :: [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#dit_tc_args"><span class="hs-identifier hs-var">dit_tc_args</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168536"><span class="hs-identifier hs-var">tc_args</span></a></span><span>
</span><span id="line-1247"></span><span>                      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_rep_tc :: TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc"><span class="hs-identifier hs-var">dit_rep_tc</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168535"><span class="hs-identifier hs-var">rep_tc</span></a></span><span>
</span><span id="line-1248"></span><span>                      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_rep_tc_args :: [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc_args"><span class="hs-identifier hs-var">dit_rep_tc_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168534"><span class="hs-identifier hs-var">rep_tc_args</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1249"></span><span>
</span><span id="line-1250"></span><span class="hs-comment">{-
Note [Looking up family instances for deriving]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tcLookupFamInstExact is an auxiliary lookup wrapper which requires
that looked-up family instances exist.  If called with a vanilla
tycon, the old type application is simply returned.

If we have
  data instance F () = ... deriving Eq
  data instance F () = ... deriving Eq
then tcLookupFamInstExact will be confused by the two matches;
but that can't happen because tcInstDecls1 doesn't call tcDeriving
if there are any overlaps.

There are two other things that might go wrong with the lookup.
First, we might see a standalone deriving clause
   deriving Eq (F ())
when there is no data instance F () in scope.

Note that it's OK to have
  data instance F [a] = ...
  deriving Eq (F [(a,b)])
where the match is not exact; the same holds for ordinary data types
with standalone deriving declarations.

Note [Deriving, type families, and partial applications]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When there are no type families, it's quite easy:

    newtype S a = MkS [a]
    -- :CoS :: S  ~ []  -- Eta-reduced

    instance Eq [a] =&gt; Eq (S a)         -- by coercion sym (Eq (:CoS a)) : Eq [a] ~ Eq (S a)
    instance Monad [] =&gt; Monad S        -- by coercion sym (Monad :CoS)  : Monad [] ~ Monad S

When type families are involved it's trickier:

    data family T a b
    newtype instance T Int a = MkT [a] deriving( Eq, Monad )
    -- :RT is the representation type for (T Int a)
    --  :Co:RT    :: :RT ~ []          -- Eta-reduced!
    --  :CoF:RT a :: T Int a ~ :RT a   -- Also eta-reduced!

    instance Eq [a] =&gt; Eq (T Int a)     -- easy by coercion
       -- d1 :: Eq [a]
       -- d2 :: Eq (T Int a) = d1 |&gt; Eq (sym (:Co:RT a ; :coF:RT a))

    instance Monad [] =&gt; Monad (T Int)  -- only if we can eta reduce???
       -- d1 :: Monad []
       -- d2 :: Monad (T Int) = d1 |&gt; Monad (sym (:Co:RT ; :coF:RT))

Note the need for the eta-reduced rule axioms.  After all, we can
write it out
    instance Monad [] =&gt; Monad (T Int)  -- only if we can eta reduce???
      return x = MkT [x]
      ... etc ...

See Note [Eta reduction for data families] in GHC.Core.Coercion.Axiom

%************************************************************************
%*                                                                      *
                Deriving data types
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-1315"></span><span>
</span><span id="line-1316"></span><span class="hs-comment">-- Once the DerivSpecMechanism is known, we can finally produce an</span><span>
</span><span id="line-1317"></span><span class="hs-comment">-- EarlyDerivSpec from it.</span><span>
</span><span id="line-1318"></span><span class="annot"><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-type">mk_eqn_from_mechanism</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecMechanism"><span class="hs-identifier hs-type">DerivSpecMechanism</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1319"></span><span id="mk_eqn_from_mechanism"><span class="annot"><span class="annottext">mk_eqn_from_mechanism :: DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-var hs-var">mk_eqn_from_mechanism</span></a></span></span><span> </span><span id="local-6989586621681168528"><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168528"><span class="hs-identifier hs-var">mechanism</span></a></span></span><span>
</span><span id="line-1320"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivEnv"><span class="hs-identifier hs-type">DerivEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">denv_overlap_mode :: DerivEnv -&gt; Maybe OverlapMode
</span><a href="GHC.Tc.Deriv.Utils.html#denv_overlap_mode"><span class="hs-identifier hs-var">denv_overlap_mode</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168527"><span class="annot"><span class="annottext">Maybe OverlapMode
</span><a href="#local-6989586621681168527"><span class="hs-identifier hs-var">overlap_mode</span></a></span></span><span>
</span><span id="line-1321"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_tvs :: DerivEnv -&gt; [TyVar]
</span><a href="GHC.Tc.Deriv.Utils.html#denv_tvs"><span class="hs-identifier hs-var">denv_tvs</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168526"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168526"><span class="hs-identifier hs-var">tvs</span></a></span></span><span>
</span><span id="line-1322"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_cls :: DerivEnv -&gt; Class
</span><a href="GHC.Tc.Deriv.Utils.html#denv_cls"><span class="hs-identifier hs-var">denv_cls</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168525"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168525"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-1323"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_inst_tys :: DerivEnv -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#denv_inst_tys"><span class="hs-identifier hs-var">denv_inst_tys</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168524"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168524"><span class="hs-identifier hs-var">inst_tys</span></a></span></span><span>
</span><span id="line-1324"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_ctxt :: DerivEnv -&gt; DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#denv_ctxt"><span class="hs-identifier hs-var">denv_ctxt</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168523"><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168523"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DerivEnv
forall (m :: * -&gt; *) r. Monad m =&gt; ReaderT r m r
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#ask"><span class="hs-identifier hs-var">ask</span></a></span><span>
</span><span id="line-1325"></span><span>       </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn ()
</span><a href="GHC.Tc.Deriv.html#doDerivInstErrorChecks1"><span class="hs-identifier hs-var">doDerivInstErrorChecks1</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168528"><span class="hs-identifier hs-var">mechanism</span></a></span><span>
</span><span id="line-1326"></span><span>       </span><span id="local-6989586621681168521"><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168521"><span class="hs-identifier hs-var">loc</span></a></span></span><span>       </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcRn SrcSpan -&gt; ReaderT DerivEnv TcRn SrcSpan
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">TcRn SrcSpan
</span><a href="GHC.Tc.Utils.Monad.html#getSrcSpanM"><span class="hs-identifier hs-var">getSrcSpanM</span></a></span><span>
</span><span id="line-1327"></span><span>       </span><span id="local-6989586621681168520"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621681168520"><span class="hs-identifier hs-var">dfun_name</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) Name -&gt; ReaderT DerivEnv TcRn Name
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">(IOEnv (Env TcGblEnv TcLclEnv) Name -&gt; ReaderT DerivEnv TcRn Name)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) Name -&gt; ReaderT DerivEnv TcRn Name
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Class
-&gt; [PredType] -&gt; SrcSpan -&gt; IOEnv (Env TcGblEnv TcLclEnv) Name
</span><a href="GHC.Tc.Utils.Env.html#newDFunName"><span class="hs-identifier hs-var">newDFunName</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168525"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168524"><span class="hs-identifier hs-var">inst_tys</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168521"><span class="hs-identifier hs-var">loc</span></a></span><span>
</span><span id="line-1328"></span><span>       </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168523"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1329"></span><span>        </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#InferContext"><span class="hs-identifier hs-type">InferContext</span></a></span><span> </span><span id="local-6989586621681168518"><span class="annot"><span class="annottext">Maybe SrcSpan
</span><a href="#local-6989586621681168518"><span class="hs-identifier hs-var">wildcard</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-1330"></span><span>          </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168517"><span class="annot"><span class="annottext">[ThetaOrigin]
</span><a href="#local-6989586621681168517"><span class="hs-identifier hs-var">inferred_constraints</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168516"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168516"><span class="hs-identifier hs-var">tvs'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168515"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168515"><span class="hs-identifier hs-var">inst_tys'</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1331"></span><span>                 </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; DerivM ([ThetaOrigin], [TyVar], [PredType])
</span><a href="GHC.Tc.Deriv.Infer.html#inferConstraints"><span class="hs-identifier hs-var">inferConstraints</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168528"><span class="hs-identifier hs-var">mechanism</span></a></span><span>
</span><span id="line-1332"></span><span>             </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">EarlyDerivSpec -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(EarlyDerivSpec -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec)
-&gt; EarlyDerivSpec -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec [ThetaOrigin] -&gt; EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#InferTheta"><span class="hs-identifier hs-var">InferTheta</span></a></span><span> </span><span class="annot"><span class="annottext">(DerivSpec [ThetaOrigin] -&gt; EarlyDerivSpec)
-&gt; DerivSpec [ThetaOrigin] -&gt; EarlyDerivSpec
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DS :: forall theta.
SrcSpan
-&gt; Name
-&gt; [TyVar]
-&gt; theta
-&gt; Class
-&gt; [PredType]
-&gt; Maybe OverlapMode
-&gt; Maybe SrcSpan
-&gt; DerivSpecMechanism
-&gt; DerivSpec theta
</span><a href="GHC.Tc.Deriv.Utils.html#DS"><span class="hs-identifier hs-type">DS</span></a></span><span>
</span><span id="line-1333"></span><span>                   </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ds_loc :: SrcSpan
</span><a href="GHC.Tc.Deriv.Utils.html#ds_loc"><span class="hs-identifier hs-var">ds_loc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168521"><span class="hs-identifier hs-var">loc</span></a></span><span>
</span><span id="line-1334"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_name :: Name
</span><a href="GHC.Tc.Deriv.Utils.html#ds_name"><span class="hs-identifier hs-var">ds_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621681168520"><span class="hs-identifier hs-var">dfun_name</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_tvs :: [TyVar]
</span><a href="GHC.Tc.Deriv.Utils.html#ds_tvs"><span class="hs-identifier hs-var">ds_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168516"><span class="hs-identifier hs-var">tvs'</span></a></span><span>
</span><span id="line-1335"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_cls :: Class
</span><a href="GHC.Tc.Deriv.Utils.html#ds_cls"><span class="hs-identifier hs-var">ds_cls</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168525"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_tys :: [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#ds_tys"><span class="hs-identifier hs-var">ds_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168515"><span class="hs-identifier hs-var">inst_tys'</span></a></span><span>
</span><span id="line-1336"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_theta :: [ThetaOrigin]
</span><a href="GHC.Tc.Deriv.Utils.html#ds_theta"><span class="hs-identifier hs-var">ds_theta</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ThetaOrigin]
</span><a href="#local-6989586621681168517"><span class="hs-identifier hs-var">inferred_constraints</span></a></span><span>
</span><span id="line-1337"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_overlap :: Maybe OverlapMode
</span><a href="GHC.Tc.Deriv.Utils.html#ds_overlap"><span class="hs-identifier hs-var">ds_overlap</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe OverlapMode
</span><a href="#local-6989586621681168527"><span class="hs-identifier hs-var">overlap_mode</span></a></span><span>
</span><span id="line-1338"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_standalone_wildcard :: Maybe SrcSpan
</span><a href="GHC.Tc.Deriv.Utils.html#ds_standalone_wildcard"><span class="hs-identifier hs-var">ds_standalone_wildcard</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe SrcSpan
</span><a href="#local-6989586621681168518"><span class="hs-identifier hs-var">wildcard</span></a></span><span>
</span><span id="line-1339"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_mechanism :: DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#ds_mechanism"><span class="hs-identifier hs-var">ds_mechanism</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168528"><span class="hs-identifier hs-var">mechanism</span></a></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1340"></span><span>
</span><span id="line-1341"></span><span>        </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#SupplyContext"><span class="hs-identifier hs-type">SupplyContext</span></a></span><span> </span><span id="local-6989586621681168504"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168504"><span class="hs-identifier hs-var">theta</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-1342"></span><span>            </span><span class="annot"><span class="annottext">EarlyDerivSpec -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(EarlyDerivSpec -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec)
-&gt; EarlyDerivSpec -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec [PredType] -&gt; EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#GivenTheta"><span class="hs-identifier hs-var">GivenTheta</span></a></span><span> </span><span class="annot"><span class="annottext">(DerivSpec [PredType] -&gt; EarlyDerivSpec)
-&gt; DerivSpec [PredType] -&gt; EarlyDerivSpec
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DS :: forall theta.
SrcSpan
-&gt; Name
-&gt; [TyVar]
-&gt; theta
-&gt; Class
-&gt; [PredType]
-&gt; Maybe OverlapMode
-&gt; Maybe SrcSpan
-&gt; DerivSpecMechanism
-&gt; DerivSpec theta
</span><a href="GHC.Tc.Deriv.Utils.html#DS"><span class="hs-identifier hs-type">DS</span></a></span><span>
</span><span id="line-1343"></span><span>                   </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ds_loc :: SrcSpan
</span><a href="GHC.Tc.Deriv.Utils.html#ds_loc"><span class="hs-identifier hs-var">ds_loc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168521"><span class="hs-identifier hs-var">loc</span></a></span><span>
</span><span id="line-1344"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_name :: Name
</span><a href="GHC.Tc.Deriv.Utils.html#ds_name"><span class="hs-identifier hs-var">ds_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621681168520"><span class="hs-identifier hs-var">dfun_name</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_tvs :: [TyVar]
</span><a href="GHC.Tc.Deriv.Utils.html#ds_tvs"><span class="hs-identifier hs-var">ds_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168526"><span class="hs-identifier hs-var">tvs</span></a></span><span>
</span><span id="line-1345"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_cls :: Class
</span><a href="GHC.Tc.Deriv.Utils.html#ds_cls"><span class="hs-identifier hs-var">ds_cls</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168525"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_tys :: [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#ds_tys"><span class="hs-identifier hs-var">ds_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168524"><span class="hs-identifier hs-var">inst_tys</span></a></span><span>
</span><span id="line-1346"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_theta :: [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#ds_theta"><span class="hs-identifier hs-var">ds_theta</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168504"><span class="hs-identifier hs-var">theta</span></a></span><span>
</span><span id="line-1347"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_overlap :: Maybe OverlapMode
</span><a href="GHC.Tc.Deriv.Utils.html#ds_overlap"><span class="hs-identifier hs-var">ds_overlap</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe OverlapMode
</span><a href="#local-6989586621681168527"><span class="hs-identifier hs-var">overlap_mode</span></a></span><span>
</span><span id="line-1348"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_standalone_wildcard :: Maybe SrcSpan
</span><a href="GHC.Tc.Deriv.Utils.html#ds_standalone_wildcard"><span class="hs-identifier hs-var">ds_standalone_wildcard</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe SrcSpan
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1349"></span><span>                   </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_mechanism :: DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#ds_mechanism"><span class="hs-identifier hs-var">ds_mechanism</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168528"><span class="hs-identifier hs-var">mechanism</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1350"></span><span>
</span><span id="line-1351"></span><span class="annot"><a href="GHC.Tc.Deriv.html#mk_eqn_stock"><span class="hs-identifier hs-type">mk_eqn_stock</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-comment">-- Information about the arguments to the class</span><span>
</span><span id="line-1352"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1353"></span><span id="mk_eqn_stock"><span class="annot"><span class="annottext">mk_eqn_stock :: DerivInstTys -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_stock"><span class="hs-identifier hs-var hs-var">mk_eqn_stock</span></a></span></span><span> </span><span id="local-6989586621681168503"><span class="annot"><span class="annottext">dit :: DerivInstTys
</span><a href="#local-6989586621681168503"><span class="hs-identifier hs-var">dit</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dit_cls_tys :: DerivInstTys -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#dit_cls_tys"><span class="hs-identifier hs-var">dit_cls_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168502"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168502"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span>
</span><span id="line-1354"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_tc"><span class="hs-identifier hs-var">dit_tc</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168501"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168501"><span class="hs-identifier hs-var">tc</span></a></span></span><span>
</span><span id="line-1355"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_rep_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc"><span class="hs-identifier hs-var">dit_rep_tc</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168500"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168500"><span class="hs-identifier hs-var">rep_tc</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1356"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivEnv"><span class="hs-identifier hs-type">DerivEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">denv_cls :: DerivEnv -&gt; Class
</span><a href="GHC.Tc.Deriv.Utils.html#denv_cls"><span class="hs-identifier hs-var">denv_cls</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168499"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168499"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-1357"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_ctxt :: DerivEnv -&gt; DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#denv_ctxt"><span class="hs-identifier hs-var">denv_ctxt</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168498"><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168498"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DerivEnv
forall (m :: * -&gt; *) r. Monad m =&gt; ReaderT r m r
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#ask"><span class="hs-identifier hs-var">ask</span></a></span><span>
</span><span id="line-1358"></span><span>       </span><span id="local-6989586621681168497"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168497"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DynFlags
forall (m :: * -&gt; *). HasDynFlags m =&gt; m DynFlags
</span><a href="GHC.Driver.Session.html#getDynFlags"><span class="hs-identifier hs-var">getDynFlags</span></a></span><span>
</span><span id="line-1359"></span><span>       </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; DerivContext
-&gt; Class
-&gt; [PredType]
-&gt; TyCon
-&gt; TyCon
-&gt; OriginativeDerivStatus
</span><a href="GHC.Tc.Deriv.Utils.html#checkOriginativeSideConditions"><span class="hs-identifier hs-var">checkOriginativeSideConditions</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168497"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168498"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168499"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168502"><span class="hs-identifier hs-var">cls_tys</span></a></span><span>
</span><span id="line-1360"></span><span>                                           </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168501"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168500"><span class="hs-identifier hs-var">rep_tc</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1361"></span><span>         </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#CanDeriveStock"><span class="hs-identifier hs-type">CanDeriveStock</span></a></span><span> </span><span id="local-6989586621681168494"><span class="annot"><span class="annottext">SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="#local-6989586621681168494"><span class="hs-identifier hs-var">gen_fn</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-var">mk_eqn_from_mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">(DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec)
-&gt; DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1362"></span><span>                                  </span><span class="annot"><span class="annottext">DerivSpecStock :: DerivInstTys
-&gt; (SrcSpan
    -&gt; TyCon
    -&gt; [PredType]
    -&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name]))
-&gt; DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#DerivSpecStock"><span class="hs-identifier hs-type">DerivSpecStock</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dsm_stock_dit :: DerivInstTys
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_stock_dit"><span class="hs-identifier hs-var">dsm_stock_dit</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168503"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1363"></span><span>                                                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dsm_stock_gen_fn :: SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_stock_gen_fn"><span class="hs-identifier hs-var">dsm_stock_gen_fn</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="#local-6989586621681168494"><span class="hs-identifier hs-var">gen_fn</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1364"></span><span>         </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#StockClassError"><span class="hs-identifier hs-type">StockClassError</span></a></span><span> </span><span id="local-6989586621681168489"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168489"><span class="hs-identifier hs-var">msg</span></a></span></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168489"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-1365"></span><span>         </span><span class="annot"><span class="annottext">OriginativeDerivStatus
</span><span class="hs-identifier">_</span></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#nonStdErr"><span class="hs-identifier hs-var">nonStdErr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168499"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1366"></span><span>
</span><span id="line-1367"></span><span class="annot"><a href="GHC.Tc.Deriv.html#mk_eqn_anyclass"><span class="hs-identifier hs-type">mk_eqn_anyclass</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1368"></span><span id="mk_eqn_anyclass"><span class="annot"><span class="annottext">mk_eqn_anyclass :: ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_anyclass"><span class="hs-identifier hs-var hs-var">mk_eqn_anyclass</span></a></span></span><span>
</span><span id="line-1369"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621681168487"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168487"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DynFlags
forall (m :: * -&gt; *). HasDynFlags m =&gt; m DynFlags
</span><a href="GHC.Driver.Session.html#getDynFlags"><span class="hs-identifier hs-var">getDynFlags</span></a></span><span>
</span><span id="line-1370"></span><span>       </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Validity
</span><a href="GHC.Tc.Deriv.Utils.html#canDeriveAnyClass"><span class="hs-identifier hs-var">canDeriveAnyClass</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168487"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1371"></span><span>         </span><span class="annot"><span class="annottext">Validity
</span><a href="GHC.Utils.Error.html#IsValid"><span class="hs-identifier hs-var">IsValid</span></a></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-var">mk_eqn_from_mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#DerivSpecAnyClass"><span class="hs-identifier hs-var">DerivSpecAnyClass</span></a></span><span>
</span><span id="line-1372"></span><span>         </span><span class="annot"><a href="GHC.Utils.Error.html#NotValid"><span class="hs-identifier hs-type">NotValid</span></a></span><span> </span><span id="local-6989586621681168482"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168482"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168482"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-1373"></span><span>
</span><span id="line-1374"></span><span class="annot"><a href="GHC.Tc.Deriv.html#mk_eqn_newtype"><span class="hs-identifier hs-type">mk_eqn_newtype</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-comment">-- Information about the arguments to the class</span><span>
</span><span id="line-1375"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>         </span><span class="hs-comment">-- The newtype's representation type</span><span>
</span><span id="line-1376"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1377"></span><span id="mk_eqn_newtype"><span class="annot"><span class="annottext">mk_eqn_newtype :: DerivInstTys -&gt; PredType -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_newtype"><span class="hs-identifier hs-var hs-var">mk_eqn_newtype</span></a></span></span><span> </span><span id="local-6989586621681168480"><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168480"><span class="hs-identifier hs-var">dit</span></a></span></span><span> </span><span id="local-6989586621681168479"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168479"><span class="hs-identifier hs-var">rep_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1378"></span><span>  </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-var">mk_eqn_from_mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">(DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec)
-&gt; DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecNewtype :: DerivInstTys -&gt; PredType -&gt; DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#DerivSpecNewtype"><span class="hs-identifier hs-type">DerivSpecNewtype</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dsm_newtype_dit :: DerivInstTys
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_newtype_dit"><span class="hs-identifier hs-var">dsm_newtype_dit</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168480"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1379"></span><span>                                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dsm_newtype_rep_ty :: PredType
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_newtype_rep_ty"><span class="hs-identifier hs-var">dsm_newtype_rep_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168479"><span class="hs-identifier hs-var">rep_ty</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1380"></span><span>
</span><span id="line-1381"></span><span class="annot"><a href="GHC.Tc.Deriv.html#mk_eqn_via"><span class="hs-identifier hs-type">mk_eqn_via</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- All arguments to the class besides the last</span><span>
</span><span id="line-1382"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>   </span><span class="hs-comment">-- The last argument to the class</span><span>
</span><span id="line-1383"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>   </span><span class="hs-comment">-- The @via@ type</span><span>
</span><span id="line-1384"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1385"></span><span id="mk_eqn_via"><span class="annot"><span class="annottext">mk_eqn_via :: [PredType]
-&gt; PredType -&gt; PredType -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_via"><span class="hs-identifier hs-var hs-var">mk_eqn_via</span></a></span></span><span> </span><span id="local-6989586621681168475"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168475"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span> </span><span id="local-6989586621681168474"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168474"><span class="hs-identifier hs-var">inst_ty</span></a></span></span><span> </span><span id="local-6989586621681168473"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168473"><span class="hs-identifier hs-var">via_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1386"></span><span>  </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-var">mk_eqn_from_mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">(DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec)
-&gt; DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecVia :: [PredType] -&gt; PredType -&gt; PredType -&gt; DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#DerivSpecVia"><span class="hs-identifier hs-type">DerivSpecVia</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dsm_via_cls_tys :: [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_via_cls_tys"><span class="hs-identifier hs-var">dsm_via_cls_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168475"><span class="hs-identifier hs-var">cls_tys</span></a></span><span>
</span><span id="line-1387"></span><span>                                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dsm_via_inst_ty :: PredType
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_via_inst_ty"><span class="hs-identifier hs-var">dsm_via_inst_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168474"><span class="hs-identifier hs-var">inst_ty</span></a></span><span>
</span><span id="line-1388"></span><span>                                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dsm_via_ty :: PredType
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_via_ty"><span class="hs-identifier hs-var">dsm_via_ty</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168473"><span class="hs-identifier hs-var">via_ty</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1389"></span><span>
</span><span id="line-1390"></span><span class="hs-comment">-- Derive an instance without a user-requested deriving strategy. This uses</span><span>
</span><span id="line-1391"></span><span class="hs-comment">-- heuristics to determine which deriving strategy to use.</span><span>
</span><span id="line-1392"></span><span class="hs-comment">-- See Note [Deriving strategies].</span><span>
</span><span id="line-1393"></span><span class="annot"><a href="GHC.Tc.Deriv.html#mk_eqn_no_strategy"><span class="hs-identifier hs-type">mk_eqn_no_strategy</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1394"></span><span id="mk_eqn_no_strategy"><span class="annot"><span class="annottext">mk_eqn_no_strategy :: ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_no_strategy"><span class="hs-identifier hs-var hs-var">mk_eqn_no_strategy</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1395"></span><span>  </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivEnv"><span class="hs-identifier hs-type">DerivEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">denv_cls :: DerivEnv -&gt; Class
</span><a href="GHC.Tc.Deriv.Utils.html#denv_cls"><span class="hs-identifier hs-var">denv_cls</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168468"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168468"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-1396"></span><span>           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_inst_tys :: DerivEnv -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#denv_inst_tys"><span class="hs-identifier hs-var">denv_inst_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168467"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168467"><span class="hs-identifier hs-var">cls_args</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DerivEnv
forall (m :: * -&gt; *) r. Monad m =&gt; ReaderT r m r
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#ask"><span class="hs-identifier hs-var">ask</span></a></span><span>
</span><span id="line-1397"></span><span>  </span><span id="local-6989586621681168466"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621681168466"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) FamInstEnvs
-&gt; ReaderT DerivEnv TcRn FamInstEnvs
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) FamInstEnvs
</span><a href="GHC.Tc.Instance.Family.html#tcGetFamInstEnvs"><span class="hs-identifier hs-var">tcGetFamInstEnvs</span></a></span><span>
</span><span id="line-1398"></span><span>
</span><span id="line-1399"></span><span>  </span><span class="hs-comment">-- First, check if the last argument is an application of a type constructor.</span><span>
</span><span id="line-1400"></span><span>  </span><span class="hs-comment">-- If not, fall back to DeriveAnyClass.</span><span>
</span><span id="line-1401"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-glyph">|</span><span>  </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168465"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168465"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168464"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168464"><span class="hs-identifier hs-var">inst_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; Maybe ([PredType], PredType)
forall a. [a] -&gt; Maybe ([a], a)
</span><a href="GHC.Utils.Misc.html#snocView"><span class="hs-identifier hs-var">snocView</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168467"><span class="hs-identifier hs-var">cls_args</span></a></span><span>
</span><span id="line-1402"></span><span>     </span><span class="hs-special">,</span><span>  </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681168463"><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168463"><span class="hs-identifier hs-var">dit</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FamInstEnvs -&gt; [PredType] -&gt; PredType -&gt; Maybe DerivInstTys
</span><a href="GHC.Tc.Deriv.html#mk_deriv_inst_tys_maybe"><span class="hs-identifier hs-var">mk_deriv_inst_tys_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621681168466"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168465"><span class="hs-identifier hs-var">cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168464"><span class="hs-identifier hs-var">inst_ty</span></a></span><span>
</span><span id="line-1403"></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-glyph">|</span><span>  </span><span class="annot"><span class="annottext">TyCon -&gt; Bool
</span><a href="GHC.Core.TyCon.html#isNewTyCon"><span class="hs-identifier hs-var">isNewTyCon</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc"><span class="hs-identifier hs-var hs-var">dit_rep_tc</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168463"><span class="hs-identifier hs-var">dit</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1404"></span><span>              </span><span class="hs-comment">-- We have a dedicated code path for newtypes (see the</span><span>
</span><span id="line-1405"></span><span>              </span><span class="hs-comment">-- documentation for mkNewTypeEqn as to why this is the case)</span><span>
</span><span id="line-1406"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; DerivInstTys -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mkNewTypeEqn"><span class="hs-identifier hs-var">mkNewTypeEqn</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168463"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1407"></span><span>
</span><span id="line-1408"></span><span>           </span><span class="hs-glyph">|</span><span>  </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1409"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-comment">-- Otherwise, our only other options are stock or anyclass.</span><span>
</span><span id="line-1410"></span><span>                 </span><span class="hs-comment">-- If it is stock, we must confirm that the last argument's</span><span>
</span><span id="line-1411"></span><span>                 </span><span class="hs-comment">-- type constructor is algebraic.</span><span>
</span><span id="line-1412"></span><span>                 </span><span class="hs-comment">-- See Note [DerivEnv and DerivSpecMechanism] in GHC.Tc.Deriv.Utils</span><span>
</span><span id="line-1413"></span><span>                 </span><span class="annot"><span class="annottext">Maybe
  (SrcSpan
   -&gt; TyCon
   -&gt; [PredType]
   -&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name]))
-&gt; ((SrcSpan
     -&gt; TyCon
     -&gt; [PredType]
     -&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name]))
    -&gt; ReaderT DerivEnv TcRn ())
-&gt; ReaderT DerivEnv TcRn ()
forall (m :: * -&gt; *) a. Monad m =&gt; Maybe a -&gt; (a -&gt; m ()) -&gt; m ()
</span><a href="GHC.Data.Maybe.html#whenIsJust"><span class="hs-identifier hs-var">whenIsJust</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class
-&gt; Maybe
     (SrcSpan
      -&gt; TyCon
      -&gt; [PredType]
      -&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name]))
</span><a href="GHC.Tc.Deriv.Utils.html#hasStockDeriving"><span class="hs-identifier hs-var">hasStockDeriving</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168468"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(((SrcSpan
   -&gt; TyCon
   -&gt; [PredType]
   -&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name]))
  -&gt; ReaderT DerivEnv TcRn ())
 -&gt; ReaderT DerivEnv TcRn ())
-&gt; ((SrcSpan
     -&gt; TyCon
     -&gt; [PredType]
     -&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name]))
    -&gt; ReaderT DerivEnv TcRn ())
-&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-1414"></span><span>                   </span><span class="annot"><span class="annottext">DerivInstTys -&gt; ReaderT DerivEnv TcRn ()
</span><a href="GHC.Tc.Deriv.html#expectNonDataFamTyCon"><span class="hs-identifier hs-var">expectNonDataFamTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168463"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1415"></span><span>                 </span><span class="annot"><span class="annottext">DerivInstTys -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168460"><span class="hs-identifier hs-var">mk_eqn_originative</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168463"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1416"></span><span>
</span><span id="line-1417"></span><span>     </span><span class="hs-glyph">|</span><span>  </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1418"></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_anyclass"><span class="hs-identifier hs-var">mk_eqn_anyclass</span></a></span><span>
</span><span id="line-1419"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1420"></span><span>    </span><span class="hs-comment">-- Use heuristics (checkOriginativeSideConditions) to determine whether</span><span>
</span><span id="line-1421"></span><span>    </span><span class="hs-comment">-- stock or anyclass deriving should be used.</span><span>
</span><span id="line-1422"></span><span>    </span><span class="annot"><a href="#local-6989586621681168460"><span class="hs-identifier hs-type">mk_eqn_originative</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1423"></span><span>    </span><span id="local-6989586621681168460"><span class="annot"><span class="annottext">mk_eqn_originative :: DerivInstTys -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168460"><span class="hs-identifier hs-var hs-var">mk_eqn_originative</span></a></span></span><span> </span><span id="local-6989586621681168459"><span class="annot"><span class="annottext">dit :: DerivInstTys
</span><a href="#local-6989586621681168459"><span class="hs-identifier hs-var">dit</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dit_cls_tys :: DerivInstTys -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#dit_cls_tys"><span class="hs-identifier hs-var">dit_cls_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168458"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168458"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span>
</span><span id="line-1424"></span><span>                                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_tc"><span class="hs-identifier hs-var">dit_tc</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168457"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168457"><span class="hs-identifier hs-var">tc</span></a></span></span><span>
</span><span id="line-1425"></span><span>                                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_rep_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc"><span class="hs-identifier hs-var">dit_rep_tc</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168456"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168456"><span class="hs-identifier hs-var">rep_tc</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1426"></span><span>      </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivEnv"><span class="hs-identifier hs-type">DerivEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">denv_cls :: DerivEnv -&gt; Class
</span><a href="GHC.Tc.Deriv.Utils.html#denv_cls"><span class="hs-identifier hs-var">denv_cls</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168455"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168455"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-1427"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_ctxt :: DerivEnv -&gt; DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#denv_ctxt"><span class="hs-identifier hs-var">denv_ctxt</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168454"><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168454"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DerivEnv
forall (m :: * -&gt; *) r. Monad m =&gt; ReaderT r m r
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#ask"><span class="hs-identifier hs-var">ask</span></a></span><span>
</span><span id="line-1428"></span><span>      </span><span id="local-6989586621681168453"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168453"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DynFlags
forall (m :: * -&gt; *). HasDynFlags m =&gt; m DynFlags
</span><a href="GHC.Driver.Session.html#getDynFlags"><span class="hs-identifier hs-var">getDynFlags</span></a></span><span>
</span><span id="line-1429"></span><span>
</span><span id="line-1430"></span><span>      </span><span class="hs-comment">-- See Note [Deriving instances for classes themselves]</span><span>
</span><span id="line-1431"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168452"><span class="annot"><span class="annottext">dac_error :: SDoc -&gt; SDoc
</span><a href="#local-6989586621681168452"><span class="hs-identifier hs-var hs-var">dac_error</span></a></span></span><span> </span><span id="local-6989586621681168451"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168451"><span class="hs-identifier hs-var">msg</span></a></span></span><span>
</span><span id="line-1432"></span><span>            </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Bool
</span><a href="GHC.Core.TyCon.html#isClassTyCon"><span class="hs-identifier hs-var">isClassTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168456"><span class="hs-identifier hs-var">rep_tc</span></a></span><span>
</span><span id="line-1433"></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168457"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;is a type class,&quot;</span></span><span>
</span><span id="line-1434"></span><span>                              </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;and can only have a derived instance&quot;</span></span><span>
</span><span id="line-1435"></span><span>                              </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%2B%24"><span class="hs-operator hs-var">$+$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;if DeriveAnyClass is enabled&quot;</span></span><span>
</span><span id="line-1436"></span><span>            </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1437"></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#nonStdErr"><span class="hs-identifier hs-var">nonStdErr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168455"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168451"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-1438"></span><span>
</span><span id="line-1439"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; DerivContext
-&gt; Class
-&gt; [PredType]
-&gt; TyCon
-&gt; TyCon
-&gt; OriginativeDerivStatus
</span><a href="GHC.Tc.Deriv.Utils.html#checkOriginativeSideConditions"><span class="hs-identifier hs-var">checkOriginativeSideConditions</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168453"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168454"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168455"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-1440"></span><span>             </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168458"><span class="hs-identifier hs-var">cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168457"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168456"><span class="hs-identifier hs-var">rep_tc</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1441"></span><span>        </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#NonDerivableClass"><span class="hs-identifier hs-type">NonDerivableClass</span></a></span><span>   </span><span id="local-6989586621681168448"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168448"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="#local-6989586621681168452"><span class="hs-identifier hs-var">dac_error</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168448"><span class="hs-identifier hs-var">msg</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1442"></span><span>        </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#StockClassError"><span class="hs-identifier hs-type">StockClassError</span></a></span><span> </span><span id="local-6989586621681168447"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168447"><span class="hs-identifier hs-var">msg</span></a></span></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168447"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-1443"></span><span>        </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#CanDeriveStock"><span class="hs-identifier hs-type">CanDeriveStock</span></a></span><span> </span><span id="local-6989586621681168446"><span class="annot"><span class="annottext">SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="#local-6989586621681168446"><span class="hs-identifier hs-var">gen_fn</span></a></span></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-var">mk_eqn_from_mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">(DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec)
-&gt; DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1444"></span><span>                                   </span><span class="annot"><span class="annottext">DerivSpecStock :: DerivInstTys
-&gt; (SrcSpan
    -&gt; TyCon
    -&gt; [PredType]
    -&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name]))
-&gt; DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#DerivSpecStock"><span class="hs-identifier hs-type">DerivSpecStock</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dsm_stock_dit :: DerivInstTys
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_stock_dit"><span class="hs-identifier hs-var">dsm_stock_dit</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168459"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1445"></span><span>                                                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dsm_stock_gen_fn :: SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_stock_gen_fn"><span class="hs-identifier hs-var">dsm_stock_gen_fn</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="#local-6989586621681168446"><span class="hs-identifier hs-var">gen_fn</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1446"></span><span>        </span><span class="annot"><span class="annottext">OriginativeDerivStatus
</span><a href="GHC.Tc.Deriv.Utils.html#CanDeriveAnyClass"><span class="hs-identifier hs-var">CanDeriveAnyClass</span></a></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-var">mk_eqn_from_mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#DerivSpecAnyClass"><span class="hs-identifier hs-var">DerivSpecAnyClass</span></a></span><span>
</span><span id="line-1447"></span><span>
</span><span id="line-1448"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
            Deriving instances for newtypes
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-1455"></span><span>
</span><span id="line-1456"></span><span class="hs-comment">-- Derive an instance for a newtype. We put this logic into its own function</span><span>
</span><span id="line-1457"></span><span class="hs-comment">-- because</span><span>
</span><span id="line-1458"></span><span class="hs-comment">--</span><span>
</span><span id="line-1459"></span><span class="hs-comment">-- (a) When no explicit deriving strategy is requested, we have special</span><span>
</span><span id="line-1460"></span><span class="hs-comment">--     heuristics for newtypes to determine which deriving strategy should</span><span>
</span><span id="line-1461"></span><span class="hs-comment">--     actually be used. See Note [Deriving strategies].</span><span>
</span><span id="line-1462"></span><span class="hs-comment">-- (b) We make an effort to give error messages specifically tailored to</span><span>
</span><span id="line-1463"></span><span class="hs-comment">--     newtypes.</span><span>
</span><span id="line-1464"></span><span class="annot"><a href="GHC.Tc.Deriv.html#mkNewTypeEqn"><span class="hs-identifier hs-type">mkNewTypeEqn</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-comment">-- Was this instance derived using an explicit @newtype@</span><span>
</span><span id="line-1465"></span><span>                     </span><span class="hs-comment">-- deriving strategy?</span><span>
</span><span id="line-1466"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.html#EarlyDerivSpec"><span class="hs-identifier hs-type">EarlyDerivSpec</span></a></span><span>
</span><span id="line-1467"></span><span id="mkNewTypeEqn"><span class="annot"><span class="annottext">mkNewTypeEqn :: Bool -&gt; DerivInstTys -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mkNewTypeEqn"><span class="hs-identifier hs-var hs-var">mkNewTypeEqn</span></a></span></span><span> </span><span id="local-6989586621681168444"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168444"><span class="hs-identifier hs-var">newtype_strat</span></a></span></span><span> </span><span id="local-6989586621681168443"><span class="annot"><span class="annottext">dit :: DerivInstTys
</span><a href="#local-6989586621681168443"><span class="hs-identifier hs-var">dit</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dit_cls_tys :: DerivInstTys -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#dit_cls_tys"><span class="hs-identifier hs-var">dit_cls_tys</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168442"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168442"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span>
</span><span id="line-1468"></span><span>                                             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_tc"><span class="hs-identifier hs-var">dit_tc</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168441"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168441"><span class="hs-identifier hs-var">tycon</span></a></span></span><span>
</span><span id="line-1469"></span><span>                                             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_rep_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc"><span class="hs-identifier hs-var">dit_rep_tc</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168440"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168440"><span class="hs-identifier hs-var">rep_tycon</span></a></span></span><span>
</span><span id="line-1470"></span><span>                                             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_rep_tc_args :: DerivInstTys -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc_args"><span class="hs-identifier hs-var">dit_rep_tc_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168439"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168439"><span class="hs-identifier hs-var">rep_tc_args</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1471"></span><span class="hs-comment">-- Want: instance (...) =&gt; cls (cls_tys ++ [tycon tc_args]) where ...</span><span>
</span><span id="line-1472"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivEnv"><span class="hs-identifier hs-type">DerivEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">denv_cls :: DerivEnv -&gt; Class
</span><a href="GHC.Tc.Deriv.Utils.html#denv_cls"><span class="hs-identifier hs-var">denv_cls</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168438"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168438"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-1473"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_ctxt :: DerivEnv -&gt; DerivContext
</span><a href="GHC.Tc.Deriv.Utils.html#denv_ctxt"><span class="hs-identifier hs-var">denv_ctxt</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168437"><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168437"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DerivEnv
forall (m :: * -&gt; *) r. Monad m =&gt; ReaderT r m r
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#ask"><span class="hs-identifier hs-var">ask</span></a></span><span>
</span><span id="line-1474"></span><span>       </span><span id="local-6989586621681168436"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168436"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DynFlags
forall (m :: * -&gt; *). HasDynFlags m =&gt; m DynFlags
</span><a href="GHC.Driver.Session.html#getDynFlags"><span class="hs-identifier hs-var">getDynFlags</span></a></span><span>
</span><span id="line-1475"></span><span>
</span><span id="line-1476"></span><span>       </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168435"><span class="annot"><span class="annottext">newtype_deriving :: Bool
</span><a href="#local-6989586621681168435"><span class="hs-identifier hs-var hs-var">newtype_deriving</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Extension -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#xopt"><span class="hs-identifier hs-var">xopt</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#GeneralizedNewtypeDeriving"><span class="hs-identifier hs-var">LangExt.GeneralizedNewtypeDeriving</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168436"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1477"></span><span>           </span><span id="local-6989586621681168432"><span class="annot"><span class="annottext">deriveAnyClass :: Bool
</span><a href="#local-6989586621681168432"><span class="hs-identifier hs-var hs-var">deriveAnyClass</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Extension -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#xopt"><span class="hs-identifier hs-var">xopt</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#DeriveAnyClass"><span class="hs-identifier hs-var">LangExt.DeriveAnyClass</span></a></span><span>             </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168436"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1478"></span><span>
</span><span id="line-1479"></span><span>           </span><span id="local-6989586621681168430"><span class="annot"><span class="annottext">bale_out :: SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168430"><span class="hs-identifier hs-var hs-var">bale_out</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var">derivingThingFailWith</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168435"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span>
</span><span id="line-1480"></span><span>
</span><span id="line-1481"></span><span>           </span><span id="local-6989586621681168429"><span class="annot"><span class="annottext">non_std :: SDoc
</span><a href="#local-6989586621681168429"><span class="hs-identifier hs-var hs-var">non_std</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#nonStdErr"><span class="hs-identifier hs-var">nonStdErr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168438"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-1482"></span><span>           </span><span id="local-6989586621681168428"><span class="annot"><span class="annottext">suggest_gnd :: SDoc
</span><a href="#local-6989586621681168428"><span class="hs-identifier hs-var hs-var">suggest_gnd</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Try GeneralizedNewtypeDeriving for GHC's&quot;</span></span><span>
</span><span id="line-1483"></span><span>                     </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;newtype-deriving extension&quot;</span></span><span>
</span><span id="line-1484"></span><span>
</span><span id="line-1485"></span><span>           </span><span class="hs-comment">-- Here is the plan for newtype derivings.  We see</span><span>
</span><span id="line-1486"></span><span>           </span><span class="hs-comment">--        newtype T a1...an = MkT (t ak+1...an)</span><span>
</span><span id="line-1487"></span><span>           </span><span class="hs-comment">--          deriving (.., C s1 .. sm, ...)</span><span>
</span><span id="line-1488"></span><span>           </span><span class="hs-comment">-- where t is a type,</span><span>
</span><span id="line-1489"></span><span>           </span><span class="hs-comment">--       ak+1...an is a suffix of a1..an, and are all tyvars</span><span>
</span><span id="line-1490"></span><span>           </span><span class="hs-comment">--       ak+1...an do not occur free in t, nor in the s1..sm</span><span>
</span><span id="line-1491"></span><span>           </span><span class="hs-comment">--       (C s1 ... sm) is a  *partial applications* of class C</span><span>
</span><span id="line-1492"></span><span>           </span><span class="hs-comment">--                      with the last parameter missing</span><span>
</span><span id="line-1493"></span><span>           </span><span class="hs-comment">--       (T a1 .. ak) matches the kind of C's last argument</span><span>
</span><span id="line-1494"></span><span>           </span><span class="hs-comment">--              (and hence so does t)</span><span>
</span><span id="line-1495"></span><span>           </span><span class="hs-comment">-- The latter kind-check has been done by deriveTyData already,</span><span>
</span><span id="line-1496"></span><span>           </span><span class="hs-comment">-- and tc_args are already trimmed</span><span>
</span><span id="line-1497"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-1498"></span><span>           </span><span class="hs-comment">-- We generate the instance</span><span>
</span><span id="line-1499"></span><span>           </span><span class="hs-comment">--       instance forall ({a1..ak} u fvs(s1..sm)).</span><span>
</span><span id="line-1500"></span><span>           </span><span class="hs-comment">--                C s1 .. sm t =&gt; C s1 .. sm (T a1...ak)</span><span>
</span><span id="line-1501"></span><span>           </span><span class="hs-comment">-- where T a1...ap is the partial application of</span><span>
</span><span id="line-1502"></span><span>           </span><span class="hs-comment">--       the LHS of the correct kind and p &gt;= k</span><span>
</span><span id="line-1503"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-1504"></span><span>           </span><span class="hs-comment">--      NB: the variables below are:</span><span>
</span><span id="line-1505"></span><span>           </span><span class="hs-comment">--              tc_tvs = [a1, ..., an]</span><span>
</span><span id="line-1506"></span><span>           </span><span class="hs-comment">--              tyvars_to_keep = [a1, ..., ak]</span><span>
</span><span id="line-1507"></span><span>           </span><span class="hs-comment">--              rep_ty = t ak .. an</span><span>
</span><span id="line-1508"></span><span>           </span><span class="hs-comment">--              deriv_tvs = fvs(s1..sm) \ tc_tvs</span><span>
</span><span id="line-1509"></span><span>           </span><span class="hs-comment">--              tys = [s1, ..., sm]</span><span>
</span><span id="line-1510"></span><span>           </span><span class="hs-comment">--              rep_fn' = t</span><span>
</span><span id="line-1511"></span><span>           </span><span class="hs-comment">--</span><span>
</span><span id="line-1512"></span><span>           </span><span class="hs-comment">-- Running example: newtype T s a = MkT (ST s a) deriving( Monad )</span><span>
</span><span id="line-1513"></span><span>           </span><span class="hs-comment">-- We generate the instance</span><span>
</span><span id="line-1514"></span><span>           </span><span class="hs-comment">--      instance Monad (ST s) =&gt; Monad (T s) where</span><span>
</span><span id="line-1515"></span><span>
</span><span id="line-1516"></span><span>           </span><span id="local-6989586621681168427"><span class="annot"><span class="annottext">nt_eta_arity :: Arity
</span><a href="#local-6989586621681168427"><span class="hs-identifier hs-var hs-var">nt_eta_arity</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Arity
</span><a href="GHC.Core.TyCon.html#newTyConEtadArity"><span class="hs-identifier hs-var">newTyConEtadArity</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168440"><span class="hs-identifier hs-var">rep_tycon</span></a></span><span>
</span><span id="line-1517"></span><span>                   </span><span class="hs-comment">-- For newtype T a b = MkT (S a a b), the TyCon</span><span>
</span><span id="line-1518"></span><span>                   </span><span class="hs-comment">-- machinery already eta-reduces the representation type, so</span><span>
</span><span id="line-1519"></span><span>                   </span><span class="hs-comment">-- we know that</span><span>
</span><span id="line-1520"></span><span>                   </span><span class="hs-comment">--      T a ~ S a a</span><span>
</span><span id="line-1521"></span><span>                   </span><span class="hs-comment">-- That's convenient here, because we may have to apply</span><span>
</span><span id="line-1522"></span><span>                   </span><span class="hs-comment">-- it to fewer than its original complement of arguments</span><span>
</span><span id="line-1523"></span><span>
</span><span id="line-1524"></span><span>           </span><span class="hs-comment">-- Note [Newtype representation]</span><span>
</span><span id="line-1525"></span><span>           </span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-1526"></span><span>           </span><span class="hs-comment">-- Need newTyConRhs (*not* a recursive representation finder)</span><span>
</span><span id="line-1527"></span><span>           </span><span class="hs-comment">-- to get the representation type. For example</span><span>
</span><span id="line-1528"></span><span>           </span><span class="hs-comment">--      newtype B = MkB Int</span><span>
</span><span id="line-1529"></span><span>           </span><span class="hs-comment">--      newtype A = MkA B deriving( Num )</span><span>
</span><span id="line-1530"></span><span>           </span><span class="hs-comment">-- We want the Num instance of B, *not* the Num instance of Int,</span><span>
</span><span id="line-1531"></span><span>           </span><span class="hs-comment">-- when making the Num instance of A!</span><span>
</span><span id="line-1532"></span><span>           </span><span id="local-6989586621681168425"><span class="annot"><span class="annottext">rep_inst_ty :: PredType
</span><a href="#local-6989586621681168425"><span class="hs-identifier hs-var hs-var">rep_inst_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [PredType] -&gt; PredType
</span><a href="GHC.Core.Type.html#newTyConInstRhs"><span class="hs-identifier hs-var">newTyConInstRhs</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168440"><span class="hs-identifier hs-var">rep_tycon</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168439"><span class="hs-identifier hs-var">rep_tc_args</span></a></span><span>
</span><span id="line-1533"></span><span>
</span><span id="line-1534"></span><span>           </span><span class="hs-comment">-------------------------------------------------------------------</span><span>
</span><span id="line-1535"></span><span>           </span><span class="hs-comment">--  Figuring out whether we can only do this newtype-deriving thing</span><span>
</span><span id="line-1536"></span><span>
</span><span id="line-1537"></span><span>           </span><span class="hs-comment">-- See Note [Determining whether newtype-deriving is appropriate]</span><span>
</span><span id="line-1538"></span><span>           </span><span id="local-6989586621681168423"><span class="annot"><span class="annottext">might_be_newtype_derivable :: Bool
</span><a href="#local-6989586621681168423"><span class="hs-identifier hs-var hs-var">might_be_newtype_derivable</span></a></span></span><span>
</span><span id="line-1539"></span><span>              </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; Bool
</span><a href="GHC.Tc.Deriv.Utils.html#non_coercible_class"><span class="hs-identifier hs-var">non_coercible_class</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168438"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1540"></span><span>              </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168421"><span class="hs-identifier hs-var">eta_ok</span></a></span><span>
</span><span id="line-1541"></span><span class="hs-comment">--            &amp;&amp; not (isRecursiveTyCon tycon)      -- Note [Recursive newtypes]</span><span>
</span><span id="line-1542"></span><span>
</span><span id="line-1543"></span><span>           </span><span class="hs-comment">-- Check that eta reduction is OK</span><span>
</span><span id="line-1544"></span><span>           </span><span id="local-6989586621681168421"><span class="annot"><span class="annottext">eta_ok :: Bool
</span><a href="#local-6989586621681168421"><span class="hs-identifier hs-var hs-var">eta_ok</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168439"><span class="hs-identifier hs-var">rep_tc_args</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; Arity -&gt; Bool
forall a. [a] -&gt; Arity -&gt; Bool
</span><a href="GHC.Utils.Misc.html#lengthAtLeast"><span class="hs-operator hs-var">`lengthAtLeast`</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621681168427"><span class="hs-identifier hs-var">nt_eta_arity</span></a></span><span>
</span><span id="line-1545"></span><span>             </span><span class="hs-comment">-- The newtype can be eta-reduced to match the number</span><span>
</span><span id="line-1546"></span><span>             </span><span class="hs-comment">--     of type argument actually supplied</span><span>
</span><span id="line-1547"></span><span>             </span><span class="hs-comment">--        newtype T a b = MkT (S [a] b) deriving( Monad )</span><span>
</span><span id="line-1548"></span><span>             </span><span class="hs-comment">--     Here the 'b' must be the same in the rep type (S [a] b)</span><span>
</span><span id="line-1549"></span><span>             </span><span class="hs-comment">--     And the [a] must not mention 'b'.  That's all handled</span><span>
</span><span id="line-1550"></span><span>             </span><span class="hs-comment">--     by nt_eta_rity.</span><span>
</span><span id="line-1551"></span><span>
</span><span id="line-1552"></span><span>           </span><span id="local-6989586621681168419"><span class="annot"><span class="annottext">cant_derive_err :: SDoc
</span><a href="#local-6989586621681168419"><span class="hs-identifier hs-var hs-var">cant_derive_err</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppUnless"><span class="hs-identifier hs-var">ppUnless</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168421"><span class="hs-identifier hs-var">eta_ok</span></a></span><span>  </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168417"><span class="hs-identifier hs-var">eta_msg</span></a></span><span>
</span><span id="line-1553"></span><span>           </span><span id="local-6989586621681168417"><span class="annot"><span class="annottext">eta_msg :: SDoc
</span><a href="#local-6989586621681168417"><span class="hs-identifier hs-var hs-var">eta_msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cannot eta-reduce the representation type enough&quot;</span></span><span>
</span><span id="line-1554"></span><span>
</span><span id="line-1555"></span><span>       </span><span class="hs-identifier">MASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">cls_tys</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">lengthIs</span><span class="hs-special">`</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">classArity</span><span> </span><span class="hs-identifier">cls</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-number">1</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1556"></span><span>       </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168444"><span class="hs-identifier hs-var">newtype_strat</span></a></span><span>
</span><span id="line-1557"></span><span>       </span><span class="hs-keyword">then</span><span>
</span><span id="line-1558"></span><span>           </span><span class="hs-comment">-- Since the user explicitly asked for GeneralizedNewtypeDeriving,</span><span>
</span><span id="line-1559"></span><span>           </span><span class="hs-comment">-- we don't need to perform all of the checks we normally would,</span><span>
</span><span id="line-1560"></span><span>           </span><span class="hs-comment">-- such as if the class being derived is known to produce ill-roled</span><span>
</span><span id="line-1561"></span><span>           </span><span class="hs-comment">-- coercions (e.g., Traversable), since we can just derive the</span><span>
</span><span id="line-1562"></span><span>           </span><span class="hs-comment">-- instance and let it error if need be.</span><span>
</span><span id="line-1563"></span><span>           </span><span class="hs-comment">-- See Note [Determining whether newtype-deriving is appropriate]</span><span>
</span><span id="line-1564"></span><span>           </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168421"><span class="hs-identifier hs-var">eta_ok</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168435"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span>
</span><span id="line-1565"></span><span>             </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">DerivInstTys -&gt; PredType -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_newtype"><span class="hs-identifier hs-var">mk_eqn_newtype</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168443"><span class="hs-identifier hs-var">dit</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168425"><span class="hs-identifier hs-var">rep_inst_ty</span></a></span><span>
</span><span id="line-1566"></span><span>             </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168430"><span class="hs-identifier hs-var">bale_out</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168419"><span class="hs-identifier hs-var">cant_derive_err</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span>
</span><span id="line-1567"></span><span>                            </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168435"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168428"><span class="hs-identifier hs-var">suggest_gnd</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1568"></span><span>       </span><span class="hs-keyword">else</span><span>
</span><span id="line-1569"></span><span>         </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168423"><span class="hs-identifier hs-var">might_be_newtype_derivable</span></a></span><span>
</span><span id="line-1570"></span><span>             </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168435"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168432"><span class="hs-identifier hs-var">deriveAnyClass</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1571"></span><span>                  </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Class -&gt; Bool
</span><a href="GHC.Tc.Deriv.Utils.html#std_class_via_coercible"><span class="hs-identifier hs-var">std_class_via_coercible</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168438"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1572"></span><span>         </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">DerivInstTys -&gt; PredType -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_newtype"><span class="hs-identifier hs-var">mk_eqn_newtype</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168443"><span class="hs-identifier hs-var">dit</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168425"><span class="hs-identifier hs-var">rep_inst_ty</span></a></span><span>
</span><span id="line-1573"></span><span>         </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DynFlags
-&gt; DerivContext
-&gt; Class
-&gt; [PredType]
-&gt; TyCon
-&gt; TyCon
-&gt; OriginativeDerivStatus
</span><a href="GHC.Tc.Deriv.Utils.html#checkOriginativeSideConditions"><span class="hs-identifier hs-var">checkOriginativeSideConditions</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168436"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">DerivContext
</span><a href="#local-6989586621681168437"><span class="hs-identifier hs-var">deriv_ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168438"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168442"><span class="hs-identifier hs-var">cls_tys</span></a></span><span>
</span><span id="line-1574"></span><span>                                                 </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168441"><span class="hs-identifier hs-var">tycon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168440"><span class="hs-identifier hs-var">rep_tycon</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1575"></span><span>               </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#StockClassError"><span class="hs-identifier hs-type">StockClassError</span></a></span><span> </span><span id="local-6989586621681168409"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168409"><span class="hs-identifier hs-var">msg</span></a></span></span><span>
</span><span id="line-1576"></span><span>                 </span><span class="hs-comment">-- There's a particular corner case where</span><span>
</span><span id="line-1577"></span><span>                 </span><span class="hs-comment">--</span><span>
</span><span id="line-1578"></span><span>                 </span><span class="hs-comment">-- 1. -XGeneralizedNewtypeDeriving and -XDeriveAnyClass are</span><span>
</span><span id="line-1579"></span><span>                 </span><span class="hs-comment">--    both enabled at the same time</span><span>
</span><span id="line-1580"></span><span>                 </span><span class="hs-comment">-- 2. We're deriving a particular stock derivable class</span><span>
</span><span id="line-1581"></span><span>                 </span><span class="hs-comment">--    (such as Functor)</span><span>
</span><span id="line-1582"></span><span>                 </span><span class="hs-comment">--</span><span>
</span><span id="line-1583"></span><span>                 </span><span class="hs-comment">-- and the previous cases won't catch it. This fixes the bug</span><span>
</span><span id="line-1584"></span><span>                 </span><span class="hs-comment">-- reported in #10598.</span><span>
</span><span id="line-1585"></span><span>                 </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168423"><span class="hs-identifier hs-var">might_be_newtype_derivable</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168435"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span>
</span><span id="line-1586"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DerivInstTys -&gt; PredType -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_newtype"><span class="hs-identifier hs-var">mk_eqn_newtype</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168443"><span class="hs-identifier hs-var">dit</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168425"><span class="hs-identifier hs-var">rep_inst_ty</span></a></span><span>
</span><span id="line-1587"></span><span>                 </span><span class="hs-comment">-- Otherwise, throw an error for a stock class</span><span>
</span><span id="line-1588"></span><span>                 </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168423"><span class="hs-identifier hs-var">might_be_newtype_derivable</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168435"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span>
</span><span id="line-1589"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168430"><span class="hs-identifier hs-var">bale_out</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168409"><span class="hs-identifier hs-var">msg</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168428"><span class="hs-identifier hs-var">suggest_gnd</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1590"></span><span>                 </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1591"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168430"><span class="hs-identifier hs-var">bale_out</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168409"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-1592"></span><span>
</span><span id="line-1593"></span><span>               </span><span class="hs-comment">-- Must use newtype deriving or DeriveAnyClass</span><span>
</span><span id="line-1594"></span><span>               </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#NonDerivableClass"><span class="hs-identifier hs-type">NonDerivableClass</span></a></span><span> </span><span id="local-6989586621681168408"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168408"><span class="hs-identifier hs-var">_msg</span></a></span></span><span>
</span><span id="line-1595"></span><span>                 </span><span class="hs-comment">-- Too hard, even with newtype deriving</span><span>
</span><span id="line-1596"></span><span>                 </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168435"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168430"><span class="hs-identifier hs-var">bale_out</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168419"><span class="hs-identifier hs-var">cant_derive_err</span></a></span><span>
</span><span id="line-1597"></span><span>                 </span><span class="hs-comment">-- Try newtype deriving!</span><span>
</span><span id="line-1598"></span><span>                 </span><span class="hs-comment">-- Here we suggest GeneralizedNewtypeDeriving even in cases</span><span>
</span><span id="line-1599"></span><span>                 </span><span class="hs-comment">-- where it may not be applicable. See #9600.</span><span>
</span><span id="line-1600"></span><span>                 </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="#local-6989586621681168430"><span class="hs-identifier hs-var">bale_out</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168429"><span class="hs-identifier hs-var">non_std</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168428"><span class="hs-identifier hs-var">suggest_gnd</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1601"></span><span>
</span><span id="line-1602"></span><span>               </span><span class="hs-comment">-- DeriveAnyClass</span><span>
</span><span id="line-1603"></span><span>               </span><span class="annot"><span class="annottext">OriginativeDerivStatus
</span><a href="GHC.Tc.Deriv.Utils.html#CanDeriveAnyClass"><span class="hs-identifier hs-var">CanDeriveAnyClass</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1604"></span><span>                 </span><span class="hs-comment">-- If both DeriveAnyClass and GeneralizedNewtypeDeriving are</span><span>
</span><span id="line-1605"></span><span>                 </span><span class="hs-comment">-- enabled, we take the diplomatic approach of defaulting to</span><span>
</span><span id="line-1606"></span><span>                 </span><span class="hs-comment">-- DeriveAnyClass, but emitting a warning about the choice.</span><span>
</span><span id="line-1607"></span><span>                 </span><span class="hs-comment">-- See Note [Deriving strategies]</span><span>
</span><span id="line-1608"></span><span>                 </span><span class="annot"><span class="annottext">Bool -&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168435"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168432"><span class="hs-identifier hs-var">deriveAnyClass</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1609"></span><span>                   </span><span class="annot"><span class="annottext">TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">WarningFlag -&gt; TcRn () -&gt; TcRn ()
forall gbl lcl.
WarningFlag -&gt; TcRnIf gbl lcl () -&gt; TcRnIf gbl lcl ()
</span><a href="GHC.Tc.Utils.Monad.html#whenWOptM"><span class="hs-identifier hs-var">whenWOptM</span></a></span><span> </span><span class="annot"><span class="annottext">WarningFlag
</span><a href="GHC.Driver.Flags.html#Opt_WarnDerivingDefaults"><span class="hs-identifier hs-var">Opt_WarnDerivingDefaults</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; TcRn ()) -&gt; TcRn () -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1610"></span><span>                     </span><span class="annot"><span class="annottext">WarnReason -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#addWarnTc"><span class="hs-identifier hs-var">addWarnTc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">WarningFlag -&gt; WarnReason
</span><a href="GHC.Driver.Flags.html#Reason"><span class="hs-identifier hs-var">Reason</span></a></span><span> </span><span class="annot"><span class="annottext">WarningFlag
</span><a href="GHC.Driver.Flags.html#Opt_WarnDerivingDefaults"><span class="hs-identifier hs-var">Opt_WarnDerivingDefaults</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcRn ()) -&gt; SDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#sep"><span class="hs-identifier hs-var">sep</span></a></span><span>
</span><span id="line-1611"></span><span>                     </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Both DeriveAnyClass and&quot;</span></span><span>
</span><span id="line-1612"></span><span>                       </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;GeneralizedNewtypeDeriving are enabled&quot;</span></span><span>
</span><span id="line-1613"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Defaulting to the DeriveAnyClass strategy&quot;</span></span><span>
</span><span id="line-1614"></span><span>                       </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;for instantiating&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Class -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168438"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-1615"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Use DerivingStrategies to pick&quot;</span></span><span>
</span><span id="line-1616"></span><span>                       </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;a different strategy&quot;</span></span><span>
</span><span id="line-1617"></span><span>                      </span><span class="hs-special">]</span><span>
</span><span id="line-1618"></span><span>                 </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-var">mk_eqn_from_mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#DerivSpecAnyClass"><span class="hs-identifier hs-var">DerivSpecAnyClass</span></a></span><span>
</span><span id="line-1619"></span><span>               </span><span class="hs-comment">-- CanDeriveStock</span><span>
</span><span id="line-1620"></span><span>               </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#CanDeriveStock"><span class="hs-identifier hs-type">CanDeriveStock</span></a></span><span> </span><span id="local-6989586621681168404"><span class="annot"><span class="annottext">SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="#local-6989586621681168404"><span class="hs-identifier hs-var">gen_fn</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
</span><a href="GHC.Tc.Deriv.html#mk_eqn_from_mechanism"><span class="hs-identifier hs-var">mk_eqn_from_mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">(DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec)
-&gt; DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn EarlyDerivSpec
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1621"></span><span>                                        </span><span class="annot"><span class="annottext">DerivSpecStock :: DerivInstTys
-&gt; (SrcSpan
    -&gt; TyCon
    -&gt; [PredType]
    -&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name]))
-&gt; DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#DerivSpecStock"><span class="hs-identifier hs-type">DerivSpecStock</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dsm_stock_dit :: DerivInstTys
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_stock_dit"><span class="hs-identifier hs-var">dsm_stock_dit</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168443"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1622"></span><span>                                                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dsm_stock_gen_fn :: SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_stock_gen_fn"><span class="hs-identifier hs-var">dsm_stock_gen_fn</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="#local-6989586621681168404"><span class="hs-identifier hs-var">gen_fn</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1623"></span><span>
</span><span id="line-1624"></span><span class="hs-comment">{-
Note [Recursive newtypes]
~~~~~~~~~~~~~~~~~~~~~~~~~
Newtype deriving works fine, even if the newtype is recursive.
e.g.    newtype S1 = S1 [T1 ()]
        newtype T1 a = T1 (StateT S1 IO a ) deriving( Monad )
Remember, too, that type families are currently (conservatively) given
a recursive flag, so this also allows newtype deriving to work
for type famillies.

We used to exclude recursive types, because we had a rather simple
minded way of generating the instance decl:
   newtype A = MkA [A]
   instance Eq [A] =&gt; Eq A      -- Makes typechecker loop!
But now we require a simple context, so it's ok.

Note [Determining whether newtype-deriving is appropriate]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When we see
  newtype NT = MkNT Foo
    deriving C
we have to decide how to perform the deriving. Do we do newtype deriving,
or do we do normal deriving? In general, we prefer to do newtype deriving
wherever possible. So, we try newtype deriving unless there's a glaring
reason not to.

&quot;Glaring reasons not to&quot; include trying to derive a class for which a
coercion-based instance doesn't make sense. These classes are listed in
the definition of non_coercible_class. They include Show (since it must
show the name of the datatype) and Traversable (since a coercion-based
Traversable instance is ill-roled).

However, non_coercible_class is ignored if the user explicitly requests
to derive an instance with GeneralizedNewtypeDeriving using the newtype
deriving strategy. In such a scenario, GHC will unquestioningly try to
derive the instance via coercions (even if the final generated code is
ill-roled!). See Note [Deriving strategies].

Note that newtype deriving might fail, even after we commit to it. This
is because the derived instance uses `coerce`, which must satisfy its
`Coercible` constraint. This is different than other deriving scenarios,
where we're sure that the resulting instance will type-check.

Note [GND and associated type families]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's possible to use GeneralizedNewtypeDeriving (GND) to derive instances for
classes with associated type families. A general recipe is:

    class C x y z where
      type T y z x
      op :: x -&gt; [y] -&gt; z

    newtype N a = MkN &lt;rep-type&gt; deriving( C )

    =====&gt;

    instance C x y &lt;rep-type&gt; =&gt; C x y (N a) where
      type T y (N a) x = T y &lt;rep-type&gt; x
      op = coerce (op :: x -&gt; [y] -&gt; &lt;rep-type&gt;)

However, we must watch out for three things:

(a) The class must not contain any data families. If it did, we'd have to
    generate a fresh data constructor name for the derived data family
    instance, and it's not clear how to do this.

(b) Each associated type family's type variables must mention the last type
    variable of the class. As an example, you wouldn't be able to use GND to
    derive an instance of this class:

      class C a b where
        type T a

    But you would be able to derive an instance of this class:

      class C a b where
        type T b

    The difference is that in the latter T mentions the last parameter of C
    (i.e., it mentions b), but the former T does not. If you tried, e.g.,

      newtype Foo x = Foo x deriving (C a)

    with the former definition of C, you'd end up with something like this:

      instance C a (Foo x) where
        type T a = T ???

    This T family instance doesn't mention the newtype (or its representation
    type) at all, so we disallow such constructions with GND.

(c) UndecidableInstances might need to be enabled. Here's a case where it is
    most definitely necessary:

      class C a where
        type T a
      newtype Loop = Loop MkLoop deriving C

      =====&gt;

      instance C Loop where
        type T Loop = T Loop

    Obviously, T Loop would send the typechecker into a loop. Unfortunately,
    you might even need UndecidableInstances even in cases where the
    typechecker would be guaranteed to terminate. For example:

      instance C Int where
        type C Int = Int
      newtype MyInt = MyInt Int deriving C

      =====&gt;

      instance C MyInt where
        type T MyInt = T Int

    GHC's termination checker isn't sophisticated enough to conclude that the
    definition of T MyInt terminates, so UndecidableInstances is required.

(d) For the time being, we do not allow the last type variable of the class to
    appear in a /kind/ of an associated type family definition. For instance:

    class C a where
      type T1 a        -- OK
      type T2 (x :: a) -- Illegal: a appears in the kind of x
      type T3 y :: a   -- Illegal: a appears in the kind of (T3 y)

    The reason we disallow this is because our current approach to deriving
    associated type family instances&#8212;i.e., by unwrapping the newtype's type
    constructor as shown above&#8212;is ill-equipped to handle the scenario when
    the last type variable appears as an implicit argument. In the worst case,
    allowing the last variable to appear in a kind can result in improper Core
    being generated (see #14728).

    There is hope for this feature being added some day, as one could
    conceivably take a newtype axiom (which witnesses a coercion between a
    newtype and its representation type) at lift that through each associated
    type at the Core level. See #14728, comment:3 for a sketch of how this
    might work. Until then, we disallow this featurette wholesale.

The same criteria apply to DerivingVia.

************************************************************************
*                                                                      *
Bindings for the various classes
*                                                                      *
************************************************************************

After all the trouble to figure out the required context for the
derived instance declarations, all that's left is to chug along to
produce them.  They will then be shoved into @tcInstDecls2@, which
will do all its usual business.

There are lots of possibilities for code to generate.  Here are
various general remarks.

PRINCIPLES:
\begin{itemize}
\item
We want derived instances of @Eq@ and @Ord@ (both v common) to be
``you-couldn't-do-better-by-hand'' efficient.

\item
Deriving @Show@---also pretty common--- should also be reasonable good code.

\item
Deriving for the other classes isn't that common or that big a deal.
\end{itemize}

PRAGMATICS:

\begin{itemize}
\item
Deriving @Ord@ is done mostly with the 1.3 @compare@ method.

\item
Deriving @Eq@ also uses @compare@, if we're deriving @Ord@, too.

\item
We {\em normally} generate code only for the non-defaulted methods;
there are some exceptions for @Eq@ and (especially) @Ord@...

\item
Sometimes we use a @_con2tag_&lt;tycon&gt;@ function, which returns a data
constructor's numeric (@Int#@) tag.  These are generated by
@gen_tag_n_con_binds@, and the heuristic for deciding if one of
these is around is given by @hasCon2TagFun@.

The examples under the different sections below will make this
clearer.

\item
Much less often (really just for deriving @Ix@), we use a
@_tag2con_&lt;tycon&gt;@ function.  See the examples.

\item
We use the renamer!!!  Reason: we're supposed to be
producing @LHsBinds Name@ for the methods, but that means
producing correctly-uniquified code on the fly.  This is entirely
possible (the @TcM@ monad has a @UniqueSupply@), but it is painful.
So, instead, we produce @MonoBinds RdrName@ then heave 'em through
the renamer.  What a great hack!
\end{itemize}
-}</span><span>
</span><span id="line-1828"></span><span>
</span><span id="line-1829"></span><span class="hs-comment">-- Generate the InstInfo for the required instance</span><span>
</span><span id="line-1830"></span><span class="hs-comment">-- plus any auxiliary bindings required</span><span>
</span><span id="line-1831"></span><span id="local-6989586621681169627"><span class="annot"><a href="GHC.Tc.Deriv.html#genInst"><span class="hs-identifier hs-type">genInst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpec"><span class="hs-identifier hs-type">DerivSpec</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681169627"><span class="hs-identifier hs-type">theta</span></a></span><span>
</span><span id="line-1832"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#ThetaType"><span class="hs-identifier hs-type">ThetaType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcPs"><span class="hs-identifier hs-type">GhcPs</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Generate.html#BagDerivStuff"><span class="hs-identifier hs-type">BagDerivStuff</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span></span><span>
</span><span id="line-1833"></span><span class="hs-comment">-- We must use continuation-returning style here to get the order in which we</span><span>
</span><span id="line-1834"></span><span class="hs-comment">-- typecheck family instances and derived instances right.</span><span>
</span><span id="line-1835"></span><span class="hs-comment">-- See Note [Staging of tcDeriving]</span><span>
</span><span id="line-1836"></span><span id="genInst"><span class="annot"><span class="annottext">genInst :: forall theta.
DerivSpec theta
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
</span><a href="GHC.Tc.Deriv.html#genInst"><span class="hs-identifier hs-var hs-var">genInst</span></a></span></span><span> </span><span id="local-6989586621681168396"><span class="annot"><span class="annottext">spec :: DerivSpec theta
</span><a href="#local-6989586621681168396"><span class="hs-identifier hs-var">spec</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DS"><span class="hs-identifier hs-type">DS</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ds_tvs :: forall theta. DerivSpec theta -&gt; [TyVar]
</span><a href="GHC.Tc.Deriv.Utils.html#ds_tvs"><span class="hs-identifier hs-var">ds_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168395"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168395"><span class="hs-identifier hs-var">tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_mechanism :: forall theta. DerivSpec theta -&gt; DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#ds_mechanism"><span class="hs-identifier hs-var">ds_mechanism</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168394"><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168394"><span class="hs-identifier hs-var">mechanism</span></a></span></span><span>
</span><span id="line-1837"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_tys :: forall theta. DerivSpec theta -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#ds_tys"><span class="hs-identifier hs-var">ds_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168393"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168393"><span class="hs-identifier hs-var">tys</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_cls :: forall theta. DerivSpec theta -&gt; Class
</span><a href="GHC.Tc.Deriv.Utils.html#ds_cls"><span class="hs-identifier hs-var">ds_cls</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168392"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168392"><span class="hs-identifier hs-var">clas</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_loc :: forall theta. DerivSpec theta -&gt; SrcSpan
</span><a href="GHC.Tc.Deriv.Utils.html#ds_loc"><span class="hs-identifier hs-var">ds_loc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168391"><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168391"><span class="hs-identifier hs-var">loc</span></a></span></span><span>
</span><span id="line-1838"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ds_standalone_wildcard :: forall theta. DerivSpec theta -&gt; Maybe SrcSpan
</span><a href="GHC.Tc.Deriv.Utils.html#ds_standalone_wildcard"><span class="hs-identifier hs-var">ds_standalone_wildcard</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168390"><span class="annot"><span class="annottext">Maybe SrcSpan
</span><a href="#local-6989586621681168390"><span class="hs-identifier hs-var">wildcard</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1839"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168389"><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168389"><span class="hs-identifier hs-var">meth_binds</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168388"><span class="annot"><span class="annottext">[LSig GhcPs]
</span><a href="#local-6989586621681168388"><span class="hs-identifier hs-var">meth_sigs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168387"><span class="annot"><span class="annottext">BagDerivStuff
</span><a href="#local-6989586621681168387"><span class="hs-identifier hs-var">deriv_stuff</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168386"><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168386"><span class="hs-identifier hs-var">unusedNames</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1840"></span><span>         </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
forall a. TcRn a -&gt; TcRn a
</span><a href="#local-6989586621681168385"><span class="hs-identifier hs-var">set_span_and_ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
 -&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name]))
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1841"></span><span>            </span><span class="annot"><span class="annottext">DerivSpecMechanism
-&gt; SrcSpan
-&gt; Class
-&gt; [PredType]
-&gt; [TyVar]
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
</span><a href="GHC.Tc.Deriv.html#genDerivStuff"><span class="hs-identifier hs-var">genDerivStuff</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168394"><span class="hs-identifier hs-var">mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168391"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168392"><span class="hs-identifier hs-var">clas</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168393"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168395"><span class="hs-identifier hs-var">tvs</span></a></span><span>
</span><span id="line-1842"></span><span>       </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168383"><span class="annot"><span class="annottext">mk_inst_info :: [PredType] -&gt; TcM (InstInfo GhcPs)
</span><a href="#local-6989586621681168383"><span class="hs-identifier hs-var hs-var">mk_inst_info</span></a></span></span><span> </span><span id="local-6989586621681168382"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168382"><span class="hs-identifier hs-var">theta</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcM (InstInfo GhcPs) -&gt; TcM (InstInfo GhcPs)
forall a. TcRn a -&gt; TcRn a
</span><a href="#local-6989586621681168385"><span class="hs-identifier hs-var">set_span_and_ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (InstInfo GhcPs) -&gt; TcM (InstInfo GhcPs))
-&gt; TcM (InstInfo GhcPs) -&gt; TcM (InstInfo GhcPs)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1843"></span><span>             </span><span id="local-6989586621681168381"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621681168381"><span class="hs-identifier hs-var">inst_spec</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; DerivSpec theta -&gt; TcM ClsInst
forall theta. [PredType] -&gt; DerivSpec theta -&gt; TcM ClsInst
</span><a href="GHC.Tc.Deriv.Utils.html#newDerivClsInst"><span class="hs-identifier hs-var">newDerivClsInst</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168382"><span class="hs-identifier hs-var">theta</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpec theta
</span><a href="#local-6989586621681168396"><span class="hs-identifier hs-var">spec</span></a></span><span>
</span><span id="line-1844"></span><span>             </span><span class="annot"><span class="annottext">Class
-&gt; ClsInst
-&gt; [PredType]
-&gt; Maybe SrcSpan
-&gt; DerivSpecMechanism
-&gt; TcRn ()
</span><a href="GHC.Tc.Deriv.html#doDerivInstErrorChecks2"><span class="hs-identifier hs-var">doDerivInstErrorChecks2</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168392"><span class="hs-identifier hs-var">clas</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621681168381"><span class="hs-identifier hs-var">inst_spec</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168382"><span class="hs-identifier hs-var">theta</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe SrcSpan
</span><a href="#local-6989586621681168390"><span class="hs-identifier hs-var">wildcard</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168394"><span class="hs-identifier hs-var">mechanism</span></a></span><span>
</span><span id="line-1845"></span><span>             </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;newder&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621681168381"><span class="hs-identifier hs-var">inst_spec</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1846"></span><span>             </span><span class="annot"><span class="annottext">InstInfo GhcPs -&gt; TcM (InstInfo GhcPs)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(InstInfo GhcPs -&gt; TcM (InstInfo GhcPs))
-&gt; InstInfo GhcPs -&gt; TcM (InstInfo GhcPs)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">InstInfo :: forall a. ClsInst -&gt; InstBindings a -&gt; InstInfo a
</span><a href="GHC.Tc.Utils.Env.html#InstInfo"><span class="hs-identifier hs-type">InstInfo</span></a></span><span>
</span><span id="line-1847"></span><span>                       </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">iSpec :: ClsInst
</span><a href="GHC.Tc.Utils.Env.html#iSpec"><span class="hs-identifier hs-var">iSpec</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621681168381"><span class="hs-identifier hs-var">inst_spec</span></a></span><span>
</span><span id="line-1848"></span><span>                       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">iBinds :: InstBindings GhcPs
</span><a href="GHC.Tc.Utils.Env.html#iBinds"><span class="hs-identifier hs-var">iBinds</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstBindings :: forall a.
[Name]
-&gt; LHsBinds a -&gt; [LSig a] -&gt; [Extension] -&gt; Bool -&gt; InstBindings a
</span><a href="GHC.Tc.Utils.Env.html#InstBindings"><span class="hs-identifier hs-type">InstBindings</span></a></span><span>
</span><span id="line-1849"></span><span>                                     </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ib_binds :: Bag (LHsBind GhcPs)
</span><a href="GHC.Tc.Utils.Env.html#ib_binds"><span class="hs-identifier hs-var">ib_binds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168389"><span class="hs-identifier hs-var">meth_binds</span></a></span><span>
</span><span id="line-1850"></span><span>                                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_tyvars :: [Name]
</span><a href="GHC.Tc.Utils.Env.html#ib_tyvars"><span class="hs-identifier hs-var">ib_tyvars</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TyVar -&gt; Name) -&gt; [TyVar] -&gt; [Name]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; Name
</span><a href="GHC.Types.Var.html#varName"><span class="hs-identifier hs-var hs-var">Var.varName</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168395"><span class="hs-identifier hs-var">tvs</span></a></span><span>
</span><span id="line-1851"></span><span>                                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_pragmas :: [LSig GhcPs]
</span><a href="GHC.Tc.Utils.Env.html#ib_pragmas"><span class="hs-identifier hs-var">ib_pragmas</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[LSig GhcPs]
</span><a href="#local-6989586621681168388"><span class="hs-identifier hs-var">meth_sigs</span></a></span><span>
</span><span id="line-1852"></span><span>                                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_extensions :: [Extension]
</span><a href="GHC.Tc.Utils.Env.html#ib_extensions"><span class="hs-identifier hs-var">ib_extensions</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Extension]
</span><a href="#local-6989586621681168377"><span class="hs-identifier hs-var">extensions</span></a></span><span>
</span><span id="line-1853"></span><span>                                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ib_derived :: Bool
</span><a href="GHC.Tc.Utils.Env.html#ib_derived"><span class="hs-identifier hs-var">ib_derived</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1854"></span><span>       </span><span class="annot"><span class="annottext">([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
-&gt; IOEnv
     (Env TcGblEnv TcLclEnv)
     ([PredType] -&gt; TcM (InstInfo GhcPs), BagDerivStuff, [Name])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[PredType] -&gt; TcM (InstInfo GhcPs)
</span><a href="#local-6989586621681168383"><span class="hs-identifier hs-var">mk_inst_info</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">BagDerivStuff
</span><a href="#local-6989586621681168387"><span class="hs-identifier hs-var">deriv_stuff</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168386"><span class="hs-identifier hs-var">unusedNames</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1855"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1856"></span><span>    </span><span class="annot"><a href="#local-6989586621681168377"><span class="hs-identifier hs-type">extensions</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#Extension"><span class="hs-identifier hs-type">LangExt.Extension</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1857"></span><span>    </span><span id="local-6989586621681168377"><span class="annot"><span class="annottext">extensions :: [Extension]
</span><a href="#local-6989586621681168377"><span class="hs-identifier hs-var hs-var">extensions</span></a></span></span><span>
</span><span id="line-1858"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; Bool
</span><a href="GHC.Tc.Deriv.Utils.html#isDerivSpecNewtype"><span class="hs-identifier hs-var">isDerivSpecNewtype</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168394"><span class="hs-identifier hs-var">mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; Bool
</span><a href="GHC.Tc.Deriv.Utils.html#isDerivSpecVia"><span class="hs-identifier hs-var">isDerivSpecVia</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168394"><span class="hs-identifier hs-var">mechanism</span></a></span><span>
</span><span id="line-1859"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span>
</span><span id="line-1860"></span><span>          </span><span class="hs-comment">-- Both these flags are needed for higher-rank uses of coerce...</span><span>
</span><span id="line-1861"></span><span>          </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#ImpredicativeTypes"><span class="hs-identifier hs-var">LangExt.ImpredicativeTypes</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#RankNTypes"><span class="hs-identifier hs-var">LangExt.RankNTypes</span></a></span><span>
</span><span id="line-1862"></span><span>          </span><span class="hs-comment">-- ...and this flag is needed to support the instance signatures</span><span>
</span><span id="line-1863"></span><span>          </span><span class="hs-comment">-- that bring type variables into scope.</span><span>
</span><span id="line-1864"></span><span>          </span><span class="hs-comment">-- See Note [Newtype-deriving instances] in GHC.Tc.Deriv.Generate</span><span>
</span><span id="line-1865"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#InstanceSigs"><span class="hs-identifier hs-var">LangExt.InstanceSigs</span></a></span><span>
</span><span id="line-1866"></span><span>        </span><span class="hs-special">]</span><span>
</span><span id="line-1867"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1868"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-1869"></span><span>
</span><span id="line-1870"></span><span>    </span><span id="local-6989586621681168371"><span class="annot"><a href="#local-6989586621681168385"><span class="hs-identifier hs-type">set_span_and_ctxt</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681168371"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681168371"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-1871"></span><span>    </span><span id="local-6989586621681168385"><span class="annot"><span class="annottext">set_span_and_ctxt :: forall a. TcRn a -&gt; TcRn a
</span><a href="#local-6989586621681168385"><span class="hs-identifier hs-var hs-var">set_span_and_ctxt</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SrcSpan -&gt; TcRn a -&gt; TcRn a
forall a. SrcSpan -&gt; TcRn a -&gt; TcRn a
</span><a href="GHC.Tc.Utils.Monad.html#setSrcSpan"><span class="hs-identifier hs-var">setSrcSpan</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168391"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn a -&gt; TcRn a) -&gt; (TcRn a -&gt; TcRn a) -&gt; TcRn a -&gt; TcRn a
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; TcRn a -&gt; TcRn a
forall a. SDoc -&gt; TcM a -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#addErrCtxt"><span class="hs-identifier hs-var">addErrCtxt</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; [PredType] -&gt; SDoc
</span><a href="GHC.Tc.TyCl.Class.html#instDeclCtxt3"><span class="hs-identifier hs-var">instDeclCtxt3</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168392"><span class="hs-identifier hs-var">clas</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168393"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1872"></span><span>
</span><span id="line-1873"></span><span class="hs-comment">-- Checks:</span><span>
</span><span id="line-1874"></span><span class="hs-comment">--</span><span>
</span><span id="line-1875"></span><span class="hs-comment">-- * All of the data constructors for a data type are in scope for a</span><span>
</span><span id="line-1876"></span><span class="hs-comment">--   standalone-derived instance (for `stock` and `newtype` deriving).</span><span>
</span><span id="line-1877"></span><span class="hs-comment">--</span><span>
</span><span id="line-1878"></span><span class="hs-comment">-- * All of the associated type families of a class are suitable for</span><span>
</span><span id="line-1879"></span><span class="hs-comment">--   GeneralizedNewtypeDeriving or DerivingVia (for `newtype` and `via`</span><span>
</span><span id="line-1880"></span><span class="hs-comment">--   deriving).</span><span>
</span><span id="line-1881"></span><span class="annot"><a href="GHC.Tc.Deriv.html#doDerivInstErrorChecks1"><span class="hs-identifier hs-type">doDerivInstErrorChecks1</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecMechanism"><span class="hs-identifier hs-type">DerivSpecMechanism</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1882"></span><span id="doDerivInstErrorChecks1"><span class="annot"><span class="annottext">doDerivInstErrorChecks1 :: DerivSpecMechanism -&gt; ReaderT DerivEnv TcRn ()
</span><a href="GHC.Tc.Deriv.html#doDerivInstErrorChecks1"><span class="hs-identifier hs-var hs-var">doDerivInstErrorChecks1</span></a></span></span><span> </span><span id="local-6989586621681168370"><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168370"><span class="hs-identifier hs-var">mechanism</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1883"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168370"><span class="hs-identifier hs-var">mechanism</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1884"></span><span>    </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecStock"><span class="hs-identifier hs-type">DerivSpecStock</span></a></span><span class="hs-special">{</span><span class="annot"><span class="annottext">dsm_stock_dit :: DerivSpecMechanism -&gt; DerivInstTys
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_stock_dit"><span class="hs-identifier hs-var">dsm_stock_dit</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168369"><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168369"><span class="hs-identifier hs-var">dit</span></a></span></span><span class="hs-special">}</span><span>
</span><span id="line-1885"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DerivInstTys -&gt; ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168368"><span class="hs-identifier hs-var">data_cons_in_scope_check</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168369"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1886"></span><span>    </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecNewtype"><span class="hs-identifier hs-type">DerivSpecNewtype</span></a></span><span class="hs-special">{</span><span class="annot"><span class="annottext">dsm_newtype_dit :: DerivSpecMechanism -&gt; DerivInstTys
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_newtype_dit"><span class="hs-identifier hs-var">dsm_newtype_dit</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168367"><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168367"><span class="hs-identifier hs-var">dit</span></a></span></span><span class="hs-special">}</span><span>
</span><span id="line-1887"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168366"><span class="hs-identifier hs-var">atf_coerce_based_error_checks</span></a></span><span>
</span><span id="line-1888"></span><span>            </span><span class="annot"><span class="annottext">DerivInstTys -&gt; ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168368"><span class="hs-identifier hs-var">data_cons_in_scope_check</span></a></span><span> </span><span class="annot"><span class="annottext">DerivInstTys
</span><a href="#local-6989586621681168367"><span class="hs-identifier hs-var">dit</span></a></span><span>
</span><span id="line-1889"></span><span>    </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecAnyClass"><span class="hs-identifier hs-type">DerivSpecAnyClass</span></a></span><span class="hs-special">{</span><span class="hs-special">}</span><span>
</span><span id="line-1890"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">() -&gt; ReaderT DerivEnv TcRn ()
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1891"></span><span>    </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecVia"><span class="hs-identifier hs-type">DerivSpecVia</span></a></span><span class="hs-special">{</span><span class="hs-special">}</span><span>
</span><span id="line-1892"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168366"><span class="hs-identifier hs-var">atf_coerce_based_error_checks</span></a></span><span>
</span><span id="line-1893"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1894"></span><span>    </span><span class="hs-comment">-- When processing a standalone deriving declaration, check that all of the</span><span>
</span><span id="line-1895"></span><span>    </span><span class="hs-comment">-- constructors for the data type are in scope. For instance:</span><span>
</span><span id="line-1896"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-1897"></span><span>    </span><span class="hs-comment">--   import M (T)</span><span>
</span><span id="line-1898"></span><span>    </span><span class="hs-comment">--   deriving stock instance Eq T</span><span>
</span><span id="line-1899"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-1900"></span><span>    </span><span class="hs-comment">-- This should be rejected, as the derived Eq instance would need to refer</span><span>
</span><span id="line-1901"></span><span>    </span><span class="hs-comment">-- to the constructors for T, which are not in scope.</span><span>
</span><span id="line-1902"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-1903"></span><span>    </span><span class="hs-comment">-- Note that the only strategies that require this check are `stock` and</span><span>
</span><span id="line-1904"></span><span>    </span><span class="hs-comment">-- `newtype`. Neither `anyclass` nor `via` require it as the code that they</span><span>
</span><span id="line-1905"></span><span>    </span><span class="hs-comment">-- generate does not require using data constructors.</span><span>
</span><span id="line-1906"></span><span>    </span><span class="annot"><a href="#local-6989586621681168368"><span class="hs-identifier hs-type">data_cons_in_scope_check</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1907"></span><span>    </span><span id="local-6989586621681168368"><span class="annot"><span class="annottext">data_cons_in_scope_check :: DerivInstTys -&gt; ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168368"><span class="hs-identifier hs-var hs-var">data_cons_in_scope_check</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dit_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_tc"><span class="hs-identifier hs-var">dit_tc</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168365"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168365"><span class="hs-identifier hs-var">tc</span></a></span></span><span>
</span><span id="line-1908"></span><span>                                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dit_rep_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc"><span class="hs-identifier hs-var">dit_rep_tc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168364"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168364"><span class="hs-identifier hs-var">rep_tc</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1909"></span><span>      </span><span id="local-6989586621681168363"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168363"><span class="hs-identifier hs-var">standalone</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DerivM Bool
</span><a href="GHC.Tc.Deriv.Utils.html#isStandaloneDeriv"><span class="hs-identifier hs-var">isStandaloneDeriv</span></a></span><span>
</span><span id="line-1910"></span><span>      </span><span class="annot"><span class="annottext">Bool -&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168363"><span class="hs-identifier hs-var">standalone</span></a></span><span> </span><span class="annot"><span class="annottext">(ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1911"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168361"><span class="annot"><span class="annottext">bale_out :: SDoc -&gt; ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168361"><span class="hs-identifier hs-var hs-var">bale_out</span></a></span></span><span> </span><span id="local-6989586621681168360"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168360"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621681168359"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168359"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; SDoc -&gt; DerivM SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErrMechanism"><span class="hs-identifier hs-var">derivingThingErrMechanism</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168370"><span class="hs-identifier hs-var">mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168360"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-1912"></span><span>                              </span><span class="annot"><span class="annottext">TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; TcRn ()
forall a. SDoc -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#failWithTc"><span class="hs-identifier hs-var">failWithTc</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168359"><span class="hs-identifier hs-var">err</span></a></span><span>
</span><span id="line-1913"></span><span>
</span><span id="line-1914"></span><span>        </span><span id="local-6989586621681168357"><span class="annot"><span class="annottext">GlobalRdrEnv
</span><a href="#local-6989586621681168357"><span class="hs-identifier hs-var">rdr_env</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) GlobalRdrEnv
-&gt; ReaderT DerivEnv TcRn GlobalRdrEnv
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) GlobalRdrEnv
</span><a href="GHC.Tc.Utils.Monad.html#getGlobalRdrEnv"><span class="hs-identifier hs-var">getGlobalRdrEnv</span></a></span><span>
</span><span id="line-1915"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168355"><span class="annot"><span class="annottext">data_con_names :: [Name]
</span><a href="#local-6989586621681168355"><span class="hs-identifier hs-var hs-var">data_con_names</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(DataCon -&gt; Name) -&gt; [DataCon] -&gt; [Name]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon -&gt; Name
</span><a href="GHC.Core.DataCon.html#dataConName"><span class="hs-identifier hs-var">dataConName</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [DataCon]
</span><a href="GHC.Core.TyCon.html#tyConDataCons"><span class="hs-identifier hs-var">tyConDataCons</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168364"><span class="hs-identifier hs-var">rep_tc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1916"></span><span>            </span><span id="local-6989586621681168352"><span class="annot"><span class="annottext">hidden_data_cons :: Bool
</span><a href="#local-6989586621681168352"><span class="hs-identifier hs-var hs-var">hidden_data_cons</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Bool
forall thing. NamedThing thing =&gt; thing -&gt; Bool
</span><a href="GHC.Types.Name.html#isWiredIn"><span class="hs-identifier hs-var">isWiredIn</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168364"><span class="hs-identifier hs-var">rep_tc</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span>
</span><span id="line-1917"></span><span>                               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Bool
</span><a href="GHC.Core.TyCon.html#isAbstractTyCon"><span class="hs-identifier hs-var">isAbstractTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168364"><span class="hs-identifier hs-var">rep_tc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span>
</span><span id="line-1918"></span><span>                                </span><span class="annot"><span class="annottext">(Name -&gt; Bool) -&gt; [Name] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="annot"><span class="annottext">Name -&gt; Bool
</span><a href="#local-6989586621681168348"><span class="hs-identifier hs-var">not_in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168355"><span class="hs-identifier hs-var">data_con_names</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1919"></span><span>            </span><span id="local-6989586621681168348"><span class="annot"><span class="annottext">not_in_scope :: Name -&gt; Bool
</span><a href="#local-6989586621681168348"><span class="hs-identifier hs-var hs-var">not_in_scope</span></a></span></span><span> </span><span id="local-6989586621681168347"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621681168347"><span class="hs-identifier hs-var">dc</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe GlobalRdrElt -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isNothing"><span class="hs-identifier hs-var">isNothing</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">GlobalRdrEnv -&gt; Name -&gt; Maybe GlobalRdrElt
</span><a href="GHC.Types.Name.Reader.html#lookupGRE_Name"><span class="hs-identifier hs-var">lookupGRE_Name</span></a></span><span> </span><span class="annot"><span class="annottext">GlobalRdrEnv
</span><a href="#local-6989586621681168357"><span class="hs-identifier hs-var">rdr_env</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621681168347"><span class="hs-identifier hs-var">dc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1920"></span><span>
</span><span id="line-1921"></span><span>        </span><span class="hs-comment">-- Make sure to also mark the data constructors as used so that GHC won't</span><span>
</span><span id="line-1922"></span><span>        </span><span class="hs-comment">-- mistakenly emit -Wunused-imports warnings about them.</span><span>
</span><span id="line-1923"></span><span>        </span><span class="annot"><span class="annottext">TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">GlobalRdrEnv -&gt; TyCon -&gt; TcRn ()
</span><a href="GHC.Rename.Env.html#addUsedDataCons"><span class="hs-identifier hs-var">addUsedDataCons</span></a></span><span> </span><span class="annot"><span class="annottext">GlobalRdrEnv
</span><a href="#local-6989586621681168357"><span class="hs-identifier hs-var">rdr_env</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168364"><span class="hs-identifier hs-var">rep_tc</span></a></span><span>
</span><span id="line-1924"></span><span>
</span><span id="line-1925"></span><span>        </span><span class="annot"><span class="annottext">Bool -&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168352"><span class="hs-identifier hs-var">hidden_data_cons</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1926"></span><span>          </span><span class="annot"><span class="annottext">SDoc -&gt; ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168361"><span class="hs-identifier hs-var">bale_out</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; ReaderT DerivEnv TcRn ())
-&gt; SDoc -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingHiddenErr"><span class="hs-identifier hs-var">derivingHiddenErr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168365"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-1927"></span><span>
</span><span id="line-1928"></span><span>    </span><span class="hs-comment">-- Ensure that a class's associated type variables are suitable for</span><span>
</span><span id="line-1929"></span><span>    </span><span class="hs-comment">-- GeneralizedNewtypeDeriving or DerivingVia. Unsurprisingly, this check is</span><span>
</span><span id="line-1930"></span><span>    </span><span class="hs-comment">-- only required for the `newtype` and `via` strategies.</span><span>
</span><span id="line-1931"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-1932"></span><span>    </span><span class="hs-comment">-- See Note [GND and associated type families]</span><span>
</span><span id="line-1933"></span><span>    </span><span class="annot"><a href="#local-6989586621681168366"><span class="hs-identifier hs-type">atf_coerce_based_error_checks</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1934"></span><span>    </span><span id="local-6989586621681168366"><span class="annot"><span class="annottext">atf_coerce_based_error_checks :: ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168366"><span class="hs-identifier hs-var hs-var">atf_coerce_based_error_checks</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1935"></span><span>      </span><span id="local-6989586621681168342"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168342"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(DerivEnv -&gt; Class) -&gt; ReaderT DerivEnv TcRn Class
forall (m :: * -&gt; *) r a. Monad m =&gt; (r -&gt; a) -&gt; ReaderT r m a
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#asks"><span class="hs-identifier hs-var">asks</span></a></span><span> </span><span class="annot"><span class="annottext">DerivEnv -&gt; Class
</span><a href="GHC.Tc.Deriv.Utils.html#denv_cls"><span class="hs-identifier hs-var hs-var">denv_cls</span></a></span><span>
</span><span id="line-1936"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168340"><span class="annot"><span class="annottext">bale_out :: SDoc -&gt; ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168340"><span class="hs-identifier hs-var hs-var">bale_out</span></a></span></span><span> </span><span id="local-6989586621681168339"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168339"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621681168338"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168338"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; SDoc -&gt; DerivM SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErrMechanism"><span class="hs-identifier hs-var">derivingThingErrMechanism</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168370"><span class="hs-identifier hs-var">mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168339"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-1937"></span><span>                            </span><span class="annot"><span class="annottext">TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; TcRn ()
forall a. SDoc -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#failWithTc"><span class="hs-identifier hs-var">failWithTc</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168338"><span class="hs-identifier hs-var">err</span></a></span><span>
</span><span id="line-1938"></span><span>
</span><span id="line-1939"></span><span>          </span><span id="local-6989586621681168337"><span class="annot"><span class="annottext">cls_tyvars :: [TyVar]
</span><a href="#local-6989586621681168337"><span class="hs-identifier hs-var hs-var">cls_tyvars</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; [TyVar]
</span><a href="GHC.Core.Class.html#classTyVars"><span class="hs-identifier hs-var hs-var">classTyVars</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168342"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-1940"></span><span>
</span><span id="line-1941"></span><span>          </span><span id="local-6989586621681168335"><span class="annot"><span class="annottext">ats_look_sensible :: Bool
</span><a href="#local-6989586621681168335"><span class="hs-identifier hs-var hs-var">ats_look_sensible</span></a></span></span><span>
</span><span id="line-1942"></span><span>             </span><span class="hs-glyph">=</span><span>  </span><span class="hs-comment">-- Check (a) from Note [GND and associated type families]</span><span>
</span><span id="line-1943"></span><span>                </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168334"><span class="hs-identifier hs-var">no_adfs</span></a></span><span>
</span><span id="line-1944"></span><span>                </span><span class="hs-comment">-- Check (b) from Note [GND and associated type families]</span><span>
</span><span id="line-1945"></span><span>             </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Maybe TyCon -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isNothing"><span class="hs-identifier hs-var">isNothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TyCon
</span><a href="#local-6989586621681168333"><span class="hs-identifier hs-var">at_without_last_cls_tv</span></a></span><span>
</span><span id="line-1946"></span><span>                </span><span class="hs-comment">-- Check (d) from Note [GND and associated type families]</span><span>
</span><span id="line-1947"></span><span>             </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Maybe TyCon -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isNothing"><span class="hs-identifier hs-var">isNothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TyCon
</span><a href="#local-6989586621681168332"><span class="hs-identifier hs-var">at_last_cls_tv_in_kinds</span></a></span><span>
</span><span id="line-1948"></span><span>
</span><span id="line-1949"></span><span>          </span><span class="hs-special">(</span><span id="local-6989586621681168331"><span class="annot"><span class="annottext">[TyCon]
</span><a href="#local-6989586621681168331"><span class="hs-identifier hs-var">adf_tcs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168330"><span class="annot"><span class="annottext">[TyCon]
</span><a href="#local-6989586621681168330"><span class="hs-identifier hs-var">atf_tcs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TyCon -&gt; Bool) -&gt; [TyCon] -&gt; ([TyCon], [TyCon])
forall a. (a -&gt; Bool) -&gt; [a] -&gt; ([a], [a])
</span><a href="../../base/src/Data.OldList.html#partition"><span class="hs-identifier hs-var">partition</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Bool
</span><a href="GHC.Core.TyCon.html#isDataFamilyTyCon"><span class="hs-identifier hs-var">isDataFamilyTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCon]
</span><a href="#local-6989586621681168329"><span class="hs-identifier hs-var">at_tcs</span></a></span><span>
</span><span id="line-1950"></span><span>          </span><span id="local-6989586621681168334"><span class="annot"><span class="annottext">no_adfs :: Bool
</span><a href="#local-6989586621681168334"><span class="hs-identifier hs-var hs-var">no_adfs</span></a></span></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyCon] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCon]
</span><a href="#local-6989586621681168331"><span class="hs-identifier hs-var">adf_tcs</span></a></span><span>
</span><span id="line-1951"></span><span>                 </span><span class="hs-comment">-- We cannot newtype-derive data family instances</span><span>
</span><span id="line-1952"></span><span>
</span><span id="line-1953"></span><span>          </span><span id="local-6989586621681168333"><span class="annot"><span class="annottext">at_without_last_cls_tv :: Maybe TyCon
</span><a href="#local-6989586621681168333"><span class="hs-identifier hs-var hs-var">at_without_last_cls_tv</span></a></span></span><span>
</span><span id="line-1954"></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TyCon -&gt; Bool) -&gt; [TyCon] -&gt; Maybe TyCon
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Maybe a
</span><a href="../../base/src/Data.Foldable.html#find"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621681168327"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168327"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621681168326"><span class="hs-identifier hs-var">last_cls_tv</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; [TyVar] -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#notElem"><span class="hs-operator hs-var">`notElem`</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TyVar]
</span><a href="GHC.Core.TyCon.html#tyConTyVars"><span class="hs-identifier hs-var hs-var">tyConTyVars</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168327"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[TyCon]
</span><a href="#local-6989586621681168330"><span class="hs-identifier hs-var">atf_tcs</span></a></span><span>
</span><span id="line-1955"></span><span>          </span><span id="local-6989586621681168332"><span class="annot"><span class="annottext">at_last_cls_tv_in_kinds :: Maybe TyCon
</span><a href="#local-6989586621681168332"><span class="hs-identifier hs-var hs-var">at_last_cls_tv_in_kinds</span></a></span></span><span>
</span><span id="line-1956"></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TyCon -&gt; Bool) -&gt; [TyCon] -&gt; Maybe TyCon
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Maybe a
</span><a href="../../base/src/Data.Foldable.html#find"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621681168324"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168324"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(TyVar -&gt; Bool) -&gt; [TyVar] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PredType -&gt; Bool
</span><a href="#local-6989586621681168323"><span class="hs-identifier hs-var">at_last_cls_tv_in_kind</span></a></span><span> </span><span class="annot"><span class="annottext">(PredType -&gt; Bool) -&gt; (TyVar -&gt; PredType) -&gt; TyVar -&gt; Bool
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; PredType
</span><a href="GHC.Types.Var.html#tyVarKind"><span class="hs-identifier hs-var">tyVarKind</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1957"></span><span>                               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [TyVar]
</span><a href="GHC.Core.TyCon.html#tyConTyVars"><span class="hs-identifier hs-var hs-var">tyConTyVars</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168324"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1958"></span><span>                        </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">PredType -&gt; Bool
</span><a href="#local-6989586621681168323"><span class="hs-identifier hs-var">at_last_cls_tv_in_kind</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; PredType
</span><a href="GHC.Core.TyCon.html#tyConResKind"><span class="hs-identifier hs-var hs-var">tyConResKind</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168324"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[TyCon]
</span><a href="#local-6989586621681168330"><span class="hs-identifier hs-var">atf_tcs</span></a></span><span>
</span><span id="line-1959"></span><span>          </span><span id="local-6989586621681168323"><span class="annot"><span class="annottext">at_last_cls_tv_in_kind :: PredType -&gt; Bool
</span><a href="#local-6989586621681168323"><span class="hs-identifier hs-var hs-var">at_last_cls_tv_in_kind</span></a></span></span><span> </span><span id="local-6989586621681168320"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168320"><span class="hs-identifier hs-var">kind</span></a></span></span><span>
</span><span id="line-1960"></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621681168326"><span class="hs-identifier hs-var">last_cls_tv</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#elemVarSet"><span class="hs-operator hs-var">`elemVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">PredType -&gt; VarSet
</span><a href="GHC.Tc.Utils.TcType.html#exactTyCoVarsOfType"><span class="hs-identifier hs-var">exactTyCoVarsOfType</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168320"><span class="hs-identifier hs-var">kind</span></a></span><span>
</span><span id="line-1961"></span><span>          </span><span id="local-6989586621681168329"><span class="annot"><span class="annottext">at_tcs :: [TyCon]
</span><a href="#local-6989586621681168329"><span class="hs-identifier hs-var hs-var">at_tcs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; [TyCon]
</span><a href="GHC.Core.Class.html#classATs"><span class="hs-identifier hs-var">classATs</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168342"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-1962"></span><span>          </span><span id="local-6989586621681168326"><span class="annot"><span class="annottext">last_cls_tv :: TyVar
</span><a href="#local-6989586621681168326"><span class="hs-identifier hs-var hs-var">last_cls_tv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">notNull</span><span> </span><span class="hs-identifier">cls_tyvars</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1963"></span><span>                        </span><span class="annot"><span class="annottext">[TyVar] -&gt; TyVar
forall a. [a] -&gt; a
</span><a href="../../base/src/GHC.List.html#last"><span class="hs-identifier hs-var">last</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168337"><span class="hs-identifier hs-var">cls_tyvars</span></a></span><span>
</span><span id="line-1964"></span><span>
</span><span id="line-1965"></span><span>          </span><span id="local-6989586621681168315"><span class="annot"><span class="annottext">cant_derive_err :: SDoc
</span><a href="#local-6989586621681168315"><span class="hs-identifier hs-var hs-var">cant_derive_err</span></a></span></span><span>
</span><span id="line-1966"></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppUnless"><span class="hs-identifier hs-var">ppUnless</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168334"><span class="hs-identifier hs-var">no_adfs</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168314"><span class="hs-identifier hs-var">adfs_msg</span></a></span><span>
</span><span id="line-1967"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; (TyCon -&gt; SDoc) -&gt; Maybe TyCon -&gt; SDoc
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><a href="../../base/src/Data.Maybe.html#maybe"><span class="hs-identifier hs-var">maybe</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
</span><a href="#local-6989586621681168313"><span class="hs-identifier hs-var">at_without_last_cls_tv_msg</span></a></span><span>
</span><span id="line-1968"></span><span>                            </span><span class="annot"><span class="annottext">Maybe TyCon
</span><a href="#local-6989586621681168333"><span class="hs-identifier hs-var">at_without_last_cls_tv</span></a></span><span>
</span><span id="line-1969"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; (TyCon -&gt; SDoc) -&gt; Maybe TyCon -&gt; SDoc
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><a href="../../base/src/Data.Maybe.html#maybe"><span class="hs-identifier hs-var">maybe</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
</span><a href="#local-6989586621681168312"><span class="hs-identifier hs-var">at_last_cls_tv_in_kinds_msg</span></a></span><span>
</span><span id="line-1970"></span><span>                            </span><span class="annot"><span class="annottext">Maybe TyCon
</span><a href="#local-6989586621681168332"><span class="hs-identifier hs-var">at_last_cls_tv_in_kinds</span></a></span><span>
</span><span id="line-1971"></span><span>                    </span><span class="hs-special">]</span><span>
</span><span id="line-1972"></span><span>          </span><span id="local-6989586621681168314"><span class="annot"><span class="annottext">adfs_msg :: SDoc
</span><a href="#local-6989586621681168314"><span class="hs-identifier hs-var hs-var">adfs_msg</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;the class has associated data types&quot;</span></span><span>
</span><span id="line-1973"></span><span>          </span><span id="local-6989586621681168313"><span class="annot"><span class="annottext">at_without_last_cls_tv_msg :: TyCon -&gt; SDoc
</span><a href="#local-6989586621681168313"><span class="hs-identifier hs-var hs-var">at_without_last_cls_tv_msg</span></a></span></span><span> </span><span id="local-6989586621681168311"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168311"><span class="hs-identifier hs-var">at_tc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span>
</span><span id="line-1974"></span><span>            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;the associated type&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168311"><span class="hs-identifier hs-var">at_tc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1975"></span><span>             </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;is not parameterized over the last type variable&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-1976"></span><span>            </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;of the class&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168342"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1977"></span><span>          </span><span id="local-6989586621681168312"><span class="annot"><span class="annottext">at_last_cls_tv_in_kinds_msg :: TyCon -&gt; SDoc
</span><a href="#local-6989586621681168312"><span class="hs-identifier hs-var hs-var">at_last_cls_tv_in_kinds_msg</span></a></span></span><span> </span><span id="local-6989586621681168310"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168310"><span class="hs-identifier hs-var">at_tc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span>
</span><span id="line-1978"></span><span>            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;the associated type&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168310"><span class="hs-identifier hs-var">at_tc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1979"></span><span>             </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;contains the last type variable&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-1980"></span><span>           </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;of the class&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168342"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1981"></span><span>             </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;in a kind, which is not (yet) allowed&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-1982"></span><span>      </span><span class="annot"><span class="annottext">Bool -&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168335"><span class="hs-identifier hs-var">ats_look_sensible</span></a></span><span> </span><span class="annot"><span class="annottext">(ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ())
-&gt; ReaderT DerivEnv TcRn () -&gt; ReaderT DerivEnv TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; ReaderT DerivEnv TcRn ()
</span><a href="#local-6989586621681168340"><span class="hs-identifier hs-var">bale_out</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168315"><span class="hs-identifier hs-var">cant_derive_err</span></a></span><span>
</span><span id="line-1983"></span><span>
</span><span id="line-1984"></span><span class="annot"><a href="GHC.Tc.Deriv.html#doDerivInstErrorChecks2"><span class="hs-identifier hs-type">doDerivInstErrorChecks2</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#ThetaType"><span class="hs-identifier hs-type">ThetaType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html#SrcSpan"><span class="hs-identifier hs-type">SrcSpan</span></a></span><span>
</span><span id="line-1985"></span><span>                        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecMechanism"><span class="hs-identifier hs-type">DerivSpecMechanism</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1986"></span><span id="doDerivInstErrorChecks2"><span class="annot"><span class="annottext">doDerivInstErrorChecks2 :: Class
-&gt; ClsInst
-&gt; [PredType]
-&gt; Maybe SrcSpan
-&gt; DerivSpecMechanism
-&gt; TcRn ()
</span><a href="GHC.Tc.Deriv.html#doDerivInstErrorChecks2"><span class="hs-identifier hs-var hs-var">doDerivInstErrorChecks2</span></a></span></span><span> </span><span id="local-6989586621681168309"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168309"><span class="hs-identifier hs-var">clas</span></a></span></span><span> </span><span id="local-6989586621681168308"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621681168308"><span class="hs-identifier hs-var">clas_inst</span></a></span></span><span> </span><span id="local-6989586621681168307"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168307"><span class="hs-identifier hs-var">theta</span></a></span></span><span> </span><span id="local-6989586621681168306"><span class="annot"><span class="annottext">Maybe SrcSpan
</span><a href="#local-6989586621681168306"><span class="hs-identifier hs-var">wildcard</span></a></span></span><span> </span><span id="local-6989586621681168305"><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168305"><span class="hs-identifier hs-var">mechanism</span></a></span></span><span>
</span><span id="line-1987"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;doDerivInstErrorChecks2&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621681168308"><span class="hs-identifier hs-var">clas_inst</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1988"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168304"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168304"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -&gt; *). HasDynFlags m =&gt; m DynFlags
</span><a href="GHC.Driver.Session.html#getDynFlags"><span class="hs-identifier hs-var">getDynFlags</span></a></span><span>
</span><span id="line-1989"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168303"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168303"><span class="hs-identifier hs-var">xpartial_sigs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Extension -&gt; TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -&gt; TcRnIf gbl lcl Bool
</span><a href="GHC.Tc.Utils.Monad.html#xoptM"><span class="hs-identifier hs-var">xoptM</span></a></span><span> </span><span class="annot"><span class="annottext">Extension
</span><a href="../../ghc-boot-th/src/GHC.LanguageExtensions.Type.html#PartialTypeSignatures"><span class="hs-identifier hs-var">LangExt.PartialTypeSignatures</span></a></span><span>
</span><span id="line-1990"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681168300"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168300"><span class="hs-identifier hs-var">wpartial_sigs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">WarningFlag -&gt; TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. WarningFlag -&gt; TcRnIf gbl lcl Bool
</span><a href="GHC.Tc.Utils.Monad.html#woptM"><span class="hs-identifier hs-var">woptM</span></a></span><span> </span><span class="annot"><span class="annottext">WarningFlag
</span><a href="GHC.Driver.Flags.html#Opt_WarnPartialTypeSignatures"><span class="hs-identifier hs-var">Opt_WarnPartialTypeSignatures</span></a></span><span>
</span><span id="line-1991"></span><span>
</span><span id="line-1992"></span><span>         </span><span class="hs-comment">-- Error if PartialTypeSignatures isn't enabled when a user tries</span><span>
</span><span id="line-1993"></span><span>         </span><span class="hs-comment">-- to write @deriving instance _ =&gt; Eq (Foo a)@. Or, if that</span><span>
</span><span id="line-1994"></span><span>         </span><span class="hs-comment">-- extension is enabled, give a warning if -Wpartial-type-signatures</span><span>
</span><span id="line-1995"></span><span>         </span><span class="hs-comment">-- is enabled.</span><span>
</span><span id="line-1996"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe SrcSpan
</span><a href="#local-6989586621681168306"><span class="hs-identifier hs-var">wildcard</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1997"></span><span>           </span><span class="annot"><span class="annottext">Maybe SrcSpan
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">() -&gt; TcRn ()
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1998"></span><span>           </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681168298"><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168298"><span class="hs-identifier hs-var">span</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SrcSpan -&gt; TcRn () -&gt; TcRn ()
forall a. SrcSpan -&gt; TcRn a -&gt; TcRn a
</span><a href="GHC.Tc.Utils.Monad.html#setSrcSpan"><span class="hs-identifier hs-var">setSrcSpan</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168298"><span class="hs-identifier hs-var">span</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; TcRn ()) -&gt; TcRn () -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1999"></span><span>             </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#checkTc"><span class="hs-identifier hs-var">checkTc</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168303"><span class="hs-identifier hs-var">xpartial_sigs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168297"><span class="hs-identifier hs-var">partial_sig_msg</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168296"><span class="hs-identifier hs-var">pts_suggestion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2000"></span><span>             </span><span class="annot"><span class="annottext">WarnReason -&gt; Bool -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#warnTc"><span class="hs-identifier hs-var">warnTc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">WarningFlag -&gt; WarnReason
</span><a href="GHC.Driver.Flags.html#Reason"><span class="hs-identifier hs-var">Reason</span></a></span><span> </span><span class="annot"><span class="annottext">WarningFlag
</span><a href="GHC.Driver.Flags.html#Opt_WarnPartialTypeSignatures"><span class="hs-identifier hs-var">Opt_WarnPartialTypeSignatures</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2001"></span><span>                    </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168300"><span class="hs-identifier hs-var">wpartial_sigs</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168297"><span class="hs-identifier hs-var">partial_sig_msg</span></a></span><span>
</span><span id="line-2002"></span><span>
</span><span id="line-2003"></span><span>         </span><span class="hs-comment">-- Check for Generic instances that are derived with an exotic</span><span>
</span><span id="line-2004"></span><span>         </span><span class="hs-comment">-- deriving strategy like DAC</span><span>
</span><span id="line-2005"></span><span>         </span><span class="hs-comment">-- See Note [Deriving strategies]</span><span>
</span><span id="line-2006"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; TcRn () -&gt; TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168294"><span class="hs-identifier hs-var">exotic_mechanism</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Class -&gt; Name
</span><a href="GHC.Core.Class.html#className"><span class="hs-identifier hs-var hs-var">className</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168309"><span class="hs-identifier hs-var">clas</span></a></span><span> </span><span class="annot"><span class="annottext">Name -&gt; [Name] -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span> </span><span class="annot"><span class="annottext">[Name]
</span><a href="GHC.Builtin.Names.html#genericClassNames"><span class="hs-identifier hs-var">genericClassNames</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; TcRn ()) -&gt; TcRn () -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-2007"></span><span>         </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#failIfTc"><span class="hs-identifier hs-var">failIfTc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#safeLanguageOn"><span class="hs-identifier hs-var">safeLanguageOn</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168304"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168289"><span class="hs-identifier hs-var">gen_inst_err</span></a></span><span>
</span><span id="line-2008"></span><span>            </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; TcRn () -&gt; TcRn ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#safeInferOn"><span class="hs-identifier hs-var">safeInferOn</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168304"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">WarningMessages -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#recordUnsafeInfer"><span class="hs-identifier hs-var">recordUnsafeInfer</span></a></span><span> </span><span class="annot"><span class="annottext">WarningMessages
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-2009"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-2010"></span><span>    </span><span id="local-6989586621681168294"><span class="annot"><span class="annottext">exotic_mechanism :: Bool
</span><a href="#local-6989586621681168294"><span class="hs-identifier hs-var hs-var">exotic_mechanism</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">(Bool -&gt; Bool) -&gt; Bool -&gt; Bool
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; Bool
</span><a href="GHC.Tc.Deriv.Utils.html#isDerivSpecStock"><span class="hs-identifier hs-var">isDerivSpecStock</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168305"><span class="hs-identifier hs-var">mechanism</span></a></span><span>
</span><span id="line-2011"></span><span>
</span><span id="line-2012"></span><span>    </span><span id="local-6989586621681168297"><span class="annot"><span class="annottext">partial_sig_msg :: SDoc
</span><a href="#local-6989586621681168297"><span class="hs-identifier hs-var hs-var">partial_sig_msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Found type wildcard&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#char"><span class="hs-identifier hs-var">char</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'_'</span></span><span class="hs-special">)</span><span>
</span><span id="line-2013"></span><span>                  </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;standing for&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[PredType] -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprTheta"><span class="hs-identifier hs-var">pprTheta</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168307"><span class="hs-identifier hs-var">theta</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2014"></span><span>
</span><span id="line-2015"></span><span>    </span><span id="local-6989586621681168296"><span class="annot"><span class="annottext">pts_suggestion :: SDoc
</span><a href="#local-6989586621681168296"><span class="hs-identifier hs-var hs-var">pts_suggestion</span></a></span></span><span>
</span><span id="line-2016"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;To use the inferred type, enable PartialTypeSignatures&quot;</span></span><span>
</span><span id="line-2017"></span><span>
</span><span id="line-2018"></span><span>    </span><span id="local-6989586621681168289"><span class="annot"><span class="annottext">gen_inst_err :: SDoc
</span><a href="#local-6989586621681168289"><span class="hs-identifier hs-var hs-var">gen_inst_err</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Generic instances can only be derived in&quot;</span></span><span>
</span><span id="line-2019"></span><span>               </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Safe Haskell using the stock strategy.&quot;</span></span><span>
</span><span id="line-2020"></span><span>
</span><span id="line-2021"></span><span id="local-6989586621681169465"><span class="annot"><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-type">derivingThingFailWith</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-comment">-- If True, add a snippet about how not even</span><span>
</span><span id="line-2022"></span><span>                              </span><span class="hs-comment">-- GeneralizedNewtypeDeriving would make this</span><span>
</span><span id="line-2023"></span><span>                              </span><span class="hs-comment">-- declaration work. This only kicks in when</span><span>
</span><span id="line-2024"></span><span>                              </span><span class="hs-comment">-- an explicit deriving strategy is not given.</span><span>
</span><span id="line-2025"></span><span>                      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span> </span><span class="hs-comment">-- The error message</span><span>
</span><span id="line-2026"></span><span>                      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681169465"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-2027"></span><span id="derivingThingFailWith"><span class="annot"><span class="annottext">derivingThingFailWith :: forall a. Bool -&gt; SDoc -&gt; DerivM a
</span><a href="GHC.Tc.Deriv.html#derivingThingFailWith"><span class="hs-identifier hs-var hs-var">derivingThingFailWith</span></a></span></span><span> </span><span id="local-6989586621681168280"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168280"><span class="hs-identifier hs-var">newtype_deriving</span></a></span></span><span> </span><span id="local-6989586621681168279"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168279"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-2028"></span><span>  </span><span id="local-6989586621681168278"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168278"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; DerivM SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErrM"><span class="hs-identifier hs-var">derivingThingErrM</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168280"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168279"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-2029"></span><span>  </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) a -&gt; DerivM a
forall (t :: (* -&gt; *) -&gt; * -&gt; *) (m :: * -&gt; *) a.
(MonadTrans t, Monad m) =&gt;
m a -&gt; t m a
</span><a href="../../transformers/src/Control.Monad.Trans.Class.html#lift"><span class="hs-identifier hs-var">lift</span></a></span><span> </span><span class="annot"><span class="annottext">(IOEnv (Env TcGblEnv TcLclEnv) a -&gt; DerivM a)
-&gt; IOEnv (Env TcGblEnv TcLclEnv) a -&gt; DerivM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; IOEnv (Env TcGblEnv TcLclEnv) a
forall a. SDoc -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#failWithTc"><span class="hs-identifier hs-var">failWithTc</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168278"><span class="hs-identifier hs-var">err</span></a></span><span>
</span><span id="line-2030"></span><span>
</span><span id="line-2031"></span><span class="annot"><a href="GHC.Tc.Deriv.html#genDerivStuff"><span class="hs-identifier hs-type">genDerivStuff</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecMechanism"><span class="hs-identifier hs-type">DerivSpecMechanism</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html#SrcSpan"><span class="hs-identifier hs-type">SrcSpan</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span>
</span><span id="line-2032"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-2033"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Binds.html#LHsBinds"><span class="hs-identifier hs-type">LHsBinds</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcPs"><span class="hs-identifier hs-type">GhcPs</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Binds.html#LSig"><span class="hs-identifier hs-type">LSig</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcPs"><span class="hs-identifier hs-type">GhcPs</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Generate.html#BagDerivStuff"><span class="hs-identifier hs-type">BagDerivStuff</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-2034"></span><span id="genDerivStuff"><span class="annot"><span class="annottext">genDerivStuff :: DerivSpecMechanism
-&gt; SrcSpan
-&gt; Class
-&gt; [PredType]
-&gt; [TyVar]
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
</span><a href="GHC.Tc.Deriv.html#genDerivStuff"><span class="hs-identifier hs-var hs-var">genDerivStuff</span></a></span></span><span> </span><span id="local-6989586621681168276"><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168276"><span class="hs-identifier hs-var">mechanism</span></a></span></span><span> </span><span id="local-6989586621681168275"><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168275"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span id="local-6989586621681168274"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168274"><span class="hs-identifier hs-var">clas</span></a></span></span><span> </span><span id="local-6989586621681168273"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168273"><span class="hs-identifier hs-var">inst_tys</span></a></span></span><span> </span><span id="local-6989586621681168272"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168272"><span class="hs-identifier hs-var">tyvars</span></a></span></span><span>
</span><span id="line-2035"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168276"><span class="hs-identifier hs-var">mechanism</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-2036"></span><span>      </span><span class="hs-comment">-- See Note [Bindings for Generalised Newtype Deriving]</span><span>
</span><span id="line-2037"></span><span>      </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecNewtype"><span class="hs-identifier hs-type">DerivSpecNewtype</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dsm_newtype_rep_ty :: DerivSpecMechanism -&gt; PredType
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_newtype_rep_ty"><span class="hs-identifier hs-var">dsm_newtype_rep_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168271"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168271"><span class="hs-identifier hs-var">rhs_ty</span></a></span></span><span class="hs-special">}</span><span>
</span><span id="line-2038"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">PredType
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
</span><a href="#local-6989586621681168270"><span class="hs-identifier hs-var">gen_newtype_or_via</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168271"><span class="hs-identifier hs-var">rhs_ty</span></a></span><span>
</span><span id="line-2039"></span><span>
</span><span id="line-2040"></span><span>      </span><span class="hs-comment">-- Try a stock deriver</span><span>
</span><span id="line-2041"></span><span>      </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecStock"><span class="hs-identifier hs-type">DerivSpecStock</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dsm_stock_dit :: DerivSpecMechanism -&gt; DerivInstTys
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_stock_dit"><span class="hs-identifier hs-var">dsm_stock_dit</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivInstTys"><span class="hs-identifier hs-type">DerivInstTys</span></a></span><span class="hs-special">{</span><span class="annot"><span class="annottext">dit_rep_tc :: DerivInstTys -&gt; TyCon
</span><a href="GHC.Tc.Deriv.Utils.html#dit_rep_tc"><span class="hs-identifier hs-var">dit_rep_tc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168269"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168269"><span class="hs-identifier hs-var">rep_tc</span></a></span></span><span class="hs-special">}</span><span>
</span><span id="line-2042"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dsm_stock_gen_fn :: DerivSpecMechanism
-&gt; SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_stock_gen_fn"><span class="hs-identifier hs-var">dsm_stock_gen_fn</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168268"><span class="annot"><span class="annottext">SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="#local-6989586621681168268"><span class="hs-identifier hs-var">gen_fn</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-2043"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681168267"><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168267"><span class="hs-identifier hs-var">binds</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168266"><span class="annot"><span class="annottext">BagDerivStuff
</span><a href="#local-6989586621681168266"><span class="hs-identifier hs-var">faminsts</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168265"><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168265"><span class="hs-identifier hs-var">field_names</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SrcSpan
-&gt; TyCon
-&gt; [PredType]
-&gt; TcM (Bag (LHsBind GhcPs), BagDerivStuff, [Name])
</span><a href="#local-6989586621681168268"><span class="hs-identifier hs-var">gen_fn</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168275"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168269"><span class="hs-identifier hs-var">rep_tc</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168273"><span class="hs-identifier hs-var">inst_tys</span></a></span><span>
</span><span id="line-2044"></span><span>              </span><span class="annot"><span class="annottext">(Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168267"><span class="hs-identifier hs-var">binds</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">BagDerivStuff
</span><a href="#local-6989586621681168266"><span class="hs-identifier hs-var">faminsts</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Name]
</span><a href="#local-6989586621681168265"><span class="hs-identifier hs-var">field_names</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2045"></span><span>
</span><span id="line-2046"></span><span>      </span><span class="hs-comment">-- Try DeriveAnyClass</span><span>
</span><span id="line-2047"></span><span>      </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="GHC.Tc.Deriv.Utils.html#DerivSpecAnyClass"><span class="hs-identifier hs-var">DerivSpecAnyClass</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-2048"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681168264"><span class="annot"><span class="annottext">mini_env :: VarEnv PredType
</span><a href="#local-6989586621681168264"><span class="hs-identifier hs-var hs-var">mini_env</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(TyVar, PredType)] -&gt; VarEnv PredType
forall a. [(TyVar, a)] -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#mkVarEnv"><span class="hs-identifier hs-var">mkVarEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; [TyVar]
</span><a href="GHC.Core.Class.html#classTyVars"><span class="hs-identifier hs-var hs-var">classTyVars</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168274"><span class="hs-identifier hs-var">clas</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; [PredType] -&gt; [(TyVar, PredType)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-operator hs-var">`zip`</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168273"><span class="hs-identifier hs-var">inst_tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2049"></span><span>            </span><span id="local-6989586621681168262"><span class="annot"><span class="annottext">mini_subst :: TCvSubst
</span><a href="#local-6989586621681168262"><span class="hs-identifier hs-var hs-var">mini_subst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; VarEnv PredType -&gt; TCvSubst
</span><a href="GHC.Core.TyCo.Subst.html#mkTvSubst"><span class="hs-identifier hs-var">mkTvSubst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VarSet -&gt; InScopeSet
</span><a href="GHC.Types.Var.Env.html#mkInScopeSet"><span class="hs-identifier hs-var">mkInScopeSet</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVar] -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#mkVarSet"><span class="hs-identifier hs-var">mkVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168272"><span class="hs-identifier hs-var">tyvars</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">VarEnv PredType
</span><a href="#local-6989586621681168264"><span class="hs-identifier hs-var">mini_env</span></a></span><span>
</span><span id="line-2050"></span><span>        </span><span id="local-6989586621681168259"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621681168259"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -&gt; *). HasDynFlags m =&gt; m DynFlags
</span><a href="GHC.Driver.Session.html#getDynFlags"><span class="hs-identifier hs-var">getDynFlags</span></a></span><span>
</span><span id="line-2051"></span><span>        </span><span id="local-6989586621681168258"><span class="annot"><span class="annottext">[[FamInst]]
</span><a href="#local-6989586621681168258"><span class="hs-identifier hs-var">tyfam_insts</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-2052"></span><span>          </span><span class="hs-comment">-- canDeriveAnyClass should ensure that this code can't be reached</span><span>
</span><span id="line-2053"></span><span>          </span><span class="hs-comment">-- unless -XDeriveAnyClass is enabled.</span><span>
</span><span id="line-2054"></span><span>          </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">isValid</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">canDeriveAnyClass</span><span> </span><span class="hs-identifier">dflags</span><span class="hs-special">)</span><span>
</span><span id="line-2055"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-string">&quot;genDerivStuff: bad derived class&quot;</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">clas</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-2056"></span><span>          </span><span class="annot"><span class="annottext">(ClassATItem -&gt; IOEnv (Env TcGblEnv TcLclEnv) [FamInst])
-&gt; [ClassATItem] -&gt; IOEnv (Env TcGblEnv TcLclEnv) [[FamInst]]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SrcSpan
-&gt; TCvSubst
-&gt; Uses
-&gt; ClassATItem
-&gt; IOEnv (Env TcGblEnv TcLclEnv) [FamInst]
</span><a href="GHC.Tc.TyCl.Class.html#tcATDefault"><span class="hs-identifier hs-var">tcATDefault</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168275"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621681168262"><span class="hs-identifier hs-var">mini_subst</span></a></span><span> </span><span class="annot"><span class="annottext">Uses
</span><a href="GHC.Types.Name.Set.html#emptyNameSet"><span class="hs-identifier hs-var">emptyNameSet</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2057"></span><span>               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; [ClassATItem]
</span><a href="GHC.Core.Class.html#classATItems"><span class="hs-identifier hs-var">classATItems</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168274"><span class="hs-identifier hs-var">clas</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2058"></span><span>        </span><span class="annot"><span class="annottext">(Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- No method bindings are needed...</span><span>
</span><span id="line-2059"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[DerivStuff] -&gt; BagDerivStuff
forall a. [a] -&gt; Bag a
</span><a href="GHC.Data.Bag.html#listToBag"><span class="hs-identifier hs-var">listToBag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(FamInst -&gt; DerivStuff) -&gt; [FamInst] -&gt; [DerivStuff]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">FamInst -&gt; DerivStuff
</span><a href="GHC.Tc.Deriv.Generate.html#DerivFamInst"><span class="hs-identifier hs-var">DerivFamInst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[[FamInst]] -&gt; [FamInst]
forall (t :: * -&gt; *) a. Foldable t =&gt; t [a] -&gt; [a]
</span><a href="../../base/src/Data.Foldable.html#concat"><span class="hs-identifier hs-var">concat</span></a></span><span> </span><span class="annot"><span class="annottext">[[FamInst]]
</span><a href="#local-6989586621681168258"><span class="hs-identifier hs-var">tyfam_insts</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-2060"></span><span>               </span><span class="hs-comment">-- ...but we may need to generate binding for associated type</span><span>
</span><span id="line-2061"></span><span>               </span><span class="hs-comment">-- family default instances.</span><span>
</span><span id="line-2062"></span><span>               </span><span class="hs-comment">-- See Note [DeriveAnyClass and default family instances]</span><span>
</span><span id="line-2063"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-2064"></span><span>
</span><span id="line-2065"></span><span>      </span><span class="hs-comment">-- Try DerivingVia</span><span>
</span><span id="line-2066"></span><span>      </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecVia"><span class="hs-identifier hs-type">DerivSpecVia</span></a></span><span class="hs-special">{</span><span class="annot"><span class="annottext">dsm_via_ty :: DerivSpecMechanism -&gt; PredType
</span><a href="GHC.Tc.Deriv.Utils.html#dsm_via_ty"><span class="hs-identifier hs-var">dsm_via_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168252"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168252"><span class="hs-identifier hs-var">via_ty</span></a></span></span><span class="hs-special">}</span><span>
</span><span id="line-2067"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">PredType
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
</span><a href="#local-6989586621681168270"><span class="hs-identifier hs-var">gen_newtype_or_via</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168252"><span class="hs-identifier hs-var">via_ty</span></a></span><span>
</span><span id="line-2068"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-2069"></span><span>    </span><span id="local-6989586621681168270"><span class="annot"><span class="annottext">gen_newtype_or_via :: PredType
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
</span><a href="#local-6989586621681168270"><span class="hs-identifier hs-var hs-var">gen_newtype_or_via</span></a></span></span><span> </span><span id="local-6989586621681168251"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168251"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-2070"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621681168250"><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168250"><span class="hs-identifier hs-var">binds</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168249"><span class="annot"><span class="annottext">[LSig GhcPs]
</span><a href="#local-6989586621681168249"><span class="hs-identifier hs-var">sigs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681168248"><span class="annot"><span class="annottext">BagDerivStuff
</span><a href="#local-6989586621681168248"><span class="hs-identifier hs-var">faminsts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SrcSpan
-&gt; Class
-&gt; [TyVar]
-&gt; [PredType]
-&gt; PredType
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff)
</span><a href="GHC.Tc.Deriv.Generate.html#gen_Newtype_binds"><span class="hs-identifier hs-var">gen_Newtype_binds</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><a href="#local-6989586621681168275"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168274"><span class="hs-identifier hs-var">clas</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621681168272"><span class="hs-identifier hs-var">tyvars</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168273"><span class="hs-identifier hs-var">inst_tys</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168251"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-2071"></span><span>      </span><span class="annot"><span class="annottext">(Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
-&gt; TcM (Bag (LHsBind GhcPs), [LSig GhcPs], BagDerivStuff, [Name])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag (LHsBind GhcPs)
</span><a href="#local-6989586621681168250"><span class="hs-identifier hs-var">binds</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[LSig GhcPs]
</span><a href="#local-6989586621681168249"><span class="hs-identifier hs-var">sigs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">BagDerivStuff
</span><a href="#local-6989586621681168248"><span class="hs-identifier hs-var">faminsts</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-2072"></span><span>
</span><span id="line-2073"></span><span class="hs-comment">{-
Note [Bindings for Generalised Newtype Deriving]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
  class Eq a =&gt; C a where
     f :: a -&gt; a
  newtype N a = MkN [a] deriving( C )
  instance Eq (N a) where ...

The 'deriving C' clause generates, in effect
  instance (C [a], Eq a) =&gt; C (N a) where
     f = coerce (f :: [a] -&gt; [a])

This generates a cast for each method, but allows the superclasse to
be worked out in the usual way.  In this case the superclass (Eq (N
a)) will be solved by the explicit Eq (N a) instance.  We do *not*
create the superclasses by casting the superclass dictionaries for the
representation type.

See the paper &quot;Safe zero-cost coercions for Haskell&quot;.

Note [DeriveAnyClass and default family instances]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When a class has a associated type family with a default instance, e.g.:

  class C a where
    type T a
    type T a = Char

then there are a couple of scenarios in which a user would expect T a to
default to Char. One is when an instance declaration for C is given without
an implementation for T:

  instance C Int

Another scenario in which this can occur is when the -XDeriveAnyClass extension
is used:

  data Example = Example deriving (C, Generic)

In the latter case, we must take care to check if C has any associated type
families with default instances, because -XDeriveAnyClass will never provide
an implementation for them. We &quot;fill in&quot; the default instances using the
tcATDefault function from GHC.Tc.TyCl.Class (which is also used in GHC.Tc.TyCl.Instance to
handle the empty instance declaration case).

Note [Deriving strategies]
~~~~~~~~~~~~~~~~~~~~~~~~~~
GHC has a notion of deriving strategies, which allow the user to explicitly
request which approach to use when deriving an instance (enabled with the
-XDerivingStrategies language extension). For more information, refer to the
original issue (#10598) or the associated wiki page:
https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler/deriving-strategies

A deriving strategy can be specified in a deriving clause:

    newtype Foo = MkFoo Bar
      deriving newtype C

Or in a standalone deriving declaration:

    deriving anyclass instance C Foo

-XDerivingStrategies also allows the use of multiple deriving clauses per data
declaration so that a user can derive some instance with one deriving strategy
and other instances with another deriving strategy. For example:

    newtype Baz = Baz Quux
      deriving          (Eq, Ord)
      deriving stock    (Read, Show)
      deriving newtype  (Num, Floating)
      deriving anyclass C

Currently, the deriving strategies are:

* stock: Have GHC implement a &quot;standard&quot; instance for a data type, if possible
  (e.g., Eq, Ord, Generic, Data, Functor, etc.)

* anyclass: Use -XDeriveAnyClass

* newtype: Use -XGeneralizedNewtypeDeriving

* via: Use -XDerivingVia

The latter two strategies (newtype and via) are referred to as the
&quot;coerce-based&quot; strategies, since they generate code that relies on the `coerce`
function. See, for instance, GHC.Tc.Deriv.Infer.inferConstraintsCoerceBased.

The former two strategies (stock and anyclass), in contrast, are
referred to as the &quot;originative&quot; strategies, since they create &quot;original&quot;
instances instead of &quot;reusing&quot; old instances (by way of `coerce`).
See, for instance, GHC.Tc.Deriv.Utils.checkOriginativeSideConditions.

If an explicit deriving strategy is not given, GHC has an algorithm it uses to
determine which strategy it will actually use. The algorithm is quite long,
so it lives in the Haskell wiki at
https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler/deriving-strategies
(&quot;The deriving strategy resolution algorithm&quot; section).

Internally, GHC uses the DerivStrategy datatype to denote a user-requested
deriving strategy, and it uses the DerivSpecMechanism datatype to denote what
GHC will use to derive the instance after taking the above steps. In other
words, GHC will always settle on a DerivSpecMechnism, even if the user did not
ask for a particular DerivStrategy (using the algorithm linked to above).

Note [Deriving instances for classes themselves]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Much of the code in GHC.Tc.Deriv assumes that deriving only works on data types.
But this assumption doesn't hold true for DeriveAnyClass, since it's perfectly
reasonable to do something like this:

  {-# LANGUAGE DeriveAnyClass #-}
  class C1 (a :: Constraint) where
  class C2 where
  deriving instance C1 C2
    -- This is equivalent to `instance C1 C2`

If DeriveAnyClass isn't enabled in the code above (i.e., it defaults to stock
deriving), we throw a special error message indicating that DeriveAnyClass is
the only way to go. We don't bother throwing this error if an explicit 'stock'
or 'newtype' keyword is used, since both options have their own perfectly
sensible error messages in the case of the above code (as C1 isn't a stock
derivable class, and C2 isn't a newtype).

************************************************************************
*                                                                      *
What con2tag/tag2con functions are available?
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-2204"></span><span>
</span><span id="line-2205"></span><span class="annot"><a href="GHC.Tc.Deriv.html#nonUnaryErr"><span class="hs-identifier hs-type">nonUnaryErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Hs.Type.html#LHsSigType"><span class="hs-identifier hs-type">LHsSigType</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-2206"></span><span id="nonUnaryErr"><span class="annot"><span class="annottext">nonUnaryErr :: LHsSigType GhcRn -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#nonUnaryErr"><span class="hs-identifier hs-var hs-var">nonUnaryErr</span></a></span></span><span> </span><span id="local-6989586621681168246"><span class="annot"><span class="annottext">LHsSigType GhcRn
</span><a href="#local-6989586621681168246"><span class="hs-identifier hs-var">ct</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">LHsSigType GhcRn -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigType GhcRn
</span><a href="#local-6989586621681168246"><span class="hs-identifier hs-var">ct</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2207"></span><span>  </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;is not a unary constraint, as expected by a deriving clause&quot;</span></span><span>
</span><span id="line-2208"></span><span>
</span><span id="line-2209"></span><span class="annot"><a href="GHC.Tc.Deriv.html#nonStdErr"><span class="hs-identifier hs-type">nonStdErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-2210"></span><span id="nonStdErr"><span class="annot"><span class="annottext">nonStdErr :: Class -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#nonStdErr"><span class="hs-identifier hs-var hs-var">nonStdErr</span></a></span></span><span> </span><span id="local-6989586621681168245"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168245"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-2211"></span><span>      </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168245"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2212"></span><span>  </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;is not a stock derivable class (Eq, Show, etc.)&quot;</span></span><span>
</span><span id="line-2213"></span><span>
</span><span id="line-2214"></span><span class="annot"><a href="GHC.Tc.Deriv.html#gndNonNewtypeErr"><span class="hs-identifier hs-type">gndNonNewtypeErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-2215"></span><span id="gndNonNewtypeErr"><span class="annot"><span class="annottext">gndNonNewtypeErr :: SDoc
</span><a href="GHC.Tc.Deriv.html#gndNonNewtypeErr"><span class="hs-identifier hs-var hs-var">gndNonNewtypeErr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-2216"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;GeneralizedNewtypeDeriving cannot be used on non-newtypes&quot;</span></span><span>
</span><span id="line-2217"></span><span>
</span><span id="line-2218"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivingNullaryErr"><span class="hs-identifier hs-type">derivingNullaryErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span>
</span><span id="line-2219"></span><span id="derivingNullaryErr"><span class="annot"><span class="annottext">derivingNullaryErr :: SDoc
</span><a href="GHC.Tc.Deriv.html#derivingNullaryErr"><span class="hs-identifier hs-var hs-var">derivingNullaryErr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Cannot derive instances for nullary classes&quot;</span></span><span>
</span><span id="line-2220"></span><span>
</span><span id="line-2221"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivingKindErr"><span class="hs-identifier hs-type">derivingKindErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Kind"><span class="hs-identifier hs-type">Kind</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span>
</span><span id="line-2222"></span><span id="derivingKindErr"><span class="annot"><span class="annottext">derivingKindErr :: TyCon -&gt; Class -&gt; [PredType] -&gt; PredType -&gt; Bool -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingKindErr"><span class="hs-identifier hs-var hs-var">derivingKindErr</span></a></span></span><span> </span><span id="local-6989586621681168243"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168243"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681168242"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168242"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621681168241"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168241"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span> </span><span id="local-6989586621681168240"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168240"><span class="hs-identifier hs-var">cls_kind</span></a></span></span><span> </span><span id="local-6989586621681168239"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168239"><span class="hs-identifier hs-var">enough_args</span></a></span></span><span>
</span><span id="line-2223"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#sep"><span class="hs-identifier hs-var">sep</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Cannot derive well-kinded instance of form&quot;</span></span><span>
</span><span id="line-2224"></span><span>                      </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; [PredType] -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprClassPred"><span class="hs-identifier hs-var">pprClassPred</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168242"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168241"><span class="hs-identifier hs-var">cls_tys</span></a></span><span>
</span><span id="line-2225"></span><span>                                    </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#parens"><span class="hs-identifier hs-var">parens</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168243"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;...&quot;</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-2226"></span><span>               </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168236"><span class="hs-identifier hs-var">gen1_suggestion</span></a></span><span>
</span><span id="line-2227"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#nest"><span class="hs-identifier hs-var">nest</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Class&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168242"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2228"></span><span>                      </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;expects an argument of kind&quot;</span></span><span>
</span><span id="line-2229"></span><span>                      </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PredType -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprKind"><span class="hs-identifier hs-var">pprKind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168240"><span class="hs-identifier hs-var">cls_kind</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-2230"></span><span>        </span><span class="hs-special">]</span><span>
</span><span id="line-2231"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-2232"></span><span>    </span><span id="local-6989586621681168236"><span class="annot"><span class="annottext">gen1_suggestion :: SDoc
</span><a href="#local-6989586621681168236"><span class="hs-identifier hs-var hs-var">gen1_suggestion</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168242"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">Class -&gt; Unique -&gt; Bool
forall a. Uniquable a =&gt; a -&gt; Unique -&gt; Bool
</span><a href="GHC.Types.Unique.html#hasKey"><span class="hs-operator hs-var">`hasKey`</span></a></span><span> </span><span class="annot"><span class="annottext">Unique
</span><a href="GHC.Builtin.Names.html#gen1ClassKey"><span class="hs-identifier hs-var">gen1ClassKey</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168239"><span class="hs-identifier hs-var">enough_args</span></a></span><span>
</span><span id="line-2233"></span><span>                    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;(Perhaps you intended to use PolyKinds)&quot;</span></span><span>
</span><span id="line-2234"></span><span>                    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">Outputable.empty</span></a></span><span>
</span><span id="line-2235"></span><span>
</span><span id="line-2236"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivingViaKindErr"><span class="hs-identifier hs-type">derivingViaKindErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Kind"><span class="hs-identifier hs-type">Kind</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Kind"><span class="hs-identifier hs-type">Kind</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span>
</span><span id="line-2237"></span><span id="derivingViaKindErr"><span class="annot"><span class="annottext">derivingViaKindErr :: Class -&gt; PredType -&gt; PredType -&gt; PredType -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingViaKindErr"><span class="hs-identifier hs-var hs-var">derivingViaKindErr</span></a></span></span><span> </span><span id="local-6989586621681168231"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168231"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621681168230"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168230"><span class="hs-identifier hs-var">cls_kind</span></a></span></span><span> </span><span id="local-6989586621681168229"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168229"><span class="hs-identifier hs-var">via_ty</span></a></span></span><span> </span><span id="local-6989586621681168228"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168228"><span class="hs-identifier hs-var">via_kind</span></a></span></span><span>
</span><span id="line-2238"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Cannot derive instance via&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PredType -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprType"><span class="hs-identifier hs-var">pprType</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168229"><span class="hs-identifier hs-var">via_ty</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-2239"></span><span>       </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Class&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168231"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2240"></span><span>               </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;expects an argument of kind&quot;</span></span><span>
</span><span id="line-2241"></span><span>               </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PredType -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprKind"><span class="hs-identifier hs-var">pprKind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168230"><span class="hs-identifier hs-var">cls_kind</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#char"><span class="hs-identifier hs-var">char</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">','</span></span><span>
</span><span id="line-2242"></span><span>      </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%2B%24"><span class="hs-operator hs-var">$+$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;but&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PredType -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprType"><span class="hs-identifier hs-var">pprType</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168229"><span class="hs-identifier hs-var">via_ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2243"></span><span>               </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;has kind&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PredType -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprKind"><span class="hs-identifier hs-var">pprKind</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168228"><span class="hs-identifier hs-var">via_kind</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-2244"></span><span>
</span><span id="line-2245"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivingEtaErr"><span class="hs-identifier hs-type">derivingEtaErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span>
</span><span id="line-2246"></span><span id="derivingEtaErr"><span class="annot"><span class="annottext">derivingEtaErr :: Class -&gt; [PredType] -&gt; PredType -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingEtaErr"><span class="hs-identifier hs-var hs-var">derivingEtaErr</span></a></span></span><span> </span><span id="local-6989586621681168225"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168225"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621681168224"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168224"><span class="hs-identifier hs-var">cls_tys</span></a></span></span><span> </span><span id="local-6989586621681168223"><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168223"><span class="hs-identifier hs-var">inst_ty</span></a></span></span><span>
</span><span id="line-2247"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#sep"><span class="hs-identifier hs-var">sep</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Cannot eta-reduce to an instance of form&quot;</span></span><span class="hs-special">,</span><span>
</span><span id="line-2248"></span><span>         </span><span class="annot"><span class="annottext">Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#nest"><span class="hs-identifier hs-var">nest</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;instance (...) =&gt;&quot;</span></span><span>
</span><span id="line-2249"></span><span>                </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Class -&gt; [PredType] -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprClassPred"><span class="hs-identifier hs-var">pprClassPred</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168225"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168224"><span class="hs-identifier hs-var">cls_tys</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType] -&gt; [PredType] -&gt; [PredType]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168223"><span class="hs-identifier hs-var">inst_ty</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-2250"></span><span>
</span><span id="line-2251"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivingThingErr"><span class="hs-identifier hs-type">derivingThingErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-2252"></span><span>                 </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#DerivStrategy"><span class="hs-identifier hs-type">DerivStrategy</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span>
</span><span id="line-2253"></span><span id="derivingThingErr"><span class="annot"><span class="annottext">derivingThingErr :: Bool
-&gt; Class
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; SDoc
-&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErr"><span class="hs-identifier hs-var hs-var">derivingThingErr</span></a></span></span><span> </span><span id="local-6989586621681168222"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168222"><span class="hs-identifier hs-var">newtype_deriving</span></a></span></span><span> </span><span id="local-6989586621681168221"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168221"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621681168220"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168220"><span class="hs-identifier hs-var">cls_args</span></a></span></span><span> </span><span id="local-6989586621681168219"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168219"><span class="hs-identifier hs-var">mb_strat</span></a></span></span><span> </span><span id="local-6989586621681168218"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168218"><span class="hs-identifier hs-var">why</span></a></span></span><span>
</span><span id="line-2254"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
-&gt; Class
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; SDoc
-&gt; SDoc
-&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErr%27"><span class="hs-identifier hs-var">derivingThingErr'</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168222"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168221"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168220"><span class="hs-identifier hs-var">cls_args</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168219"><span class="hs-identifier hs-var">mb_strat</span></a></span><span>
</span><span id="line-2255"></span><span>                      </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc
-&gt; (DerivStrategy GhcTc -&gt; SDoc)
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; SDoc
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><a href="../../base/src/Data.Maybe.html#maybe"><span class="hs-identifier hs-var">maybe</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span> </span><span class="annot"><span class="annottext">DerivStrategy GhcTc -&gt; SDoc
forall a. DerivStrategy a -&gt; SDoc
</span><a href="GHC.Hs.Decls.html#derivStrategyName"><span class="hs-identifier hs-var">derivStrategyName</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168219"><span class="hs-identifier hs-var">mb_strat</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168218"><span class="hs-identifier hs-var">why</span></a></span><span>
</span><span id="line-2256"></span><span>
</span><span id="line-2257"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivingThingErrM"><span class="hs-identifier hs-type">derivingThingErrM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span>
</span><span id="line-2258"></span><span id="derivingThingErrM"><span class="annot"><span class="annottext">derivingThingErrM :: Bool -&gt; SDoc -&gt; DerivM SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErrM"><span class="hs-identifier hs-var hs-var">derivingThingErrM</span></a></span></span><span> </span><span id="local-6989586621681168215"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168215"><span class="hs-identifier hs-var">newtype_deriving</span></a></span></span><span> </span><span id="local-6989586621681168214"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168214"><span class="hs-identifier hs-var">why</span></a></span></span><span>
</span><span id="line-2259"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivEnv"><span class="hs-identifier hs-type">DerivEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">denv_cls :: DerivEnv -&gt; Class
</span><a href="GHC.Tc.Deriv.Utils.html#denv_cls"><span class="hs-identifier hs-var">denv_cls</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168213"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168213"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-2260"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_inst_tys :: DerivEnv -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#denv_inst_tys"><span class="hs-identifier hs-var">denv_inst_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168212"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168212"><span class="hs-identifier hs-var">cls_args</span></a></span></span><span>
</span><span id="line-2261"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_strat :: DerivEnv -&gt; Maybe (DerivStrategy GhcTc)
</span><a href="GHC.Tc.Deriv.Utils.html#denv_strat"><span class="hs-identifier hs-var">denv_strat</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168211"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168211"><span class="hs-identifier hs-var">mb_strat</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DerivEnv
forall (m :: * -&gt; *) r. Monad m =&gt; ReaderT r m r
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#ask"><span class="hs-identifier hs-var">ask</span></a></span><span>
</span><span id="line-2262"></span><span>       </span><span class="annot"><span class="annottext">SDoc -&gt; DerivM SDoc
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; DerivM SDoc) -&gt; SDoc -&gt; DerivM SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
-&gt; Class
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; SDoc
-&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErr"><span class="hs-identifier hs-var">derivingThingErr</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168215"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168213"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168212"><span class="hs-identifier hs-var">cls_args</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168211"><span class="hs-identifier hs-var">mb_strat</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168214"><span class="hs-identifier hs-var">why</span></a></span><span>
</span><span id="line-2263"></span><span>
</span><span id="line-2264"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivingThingErrMechanism"><span class="hs-identifier hs-type">derivingThingErrMechanism</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivSpecMechanism"><span class="hs-identifier hs-type">DerivSpecMechanism</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivM"><span class="hs-identifier hs-type">DerivM</span></a></span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span>
</span><span id="line-2265"></span><span id="derivingThingErrMechanism"><span class="annot"><span class="annottext">derivingThingErrMechanism :: DerivSpecMechanism -&gt; SDoc -&gt; DerivM SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErrMechanism"><span class="hs-identifier hs-var hs-var">derivingThingErrMechanism</span></a></span></span><span> </span><span id="local-6989586621681168210"><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168210"><span class="hs-identifier hs-var">mechanism</span></a></span></span><span> </span><span id="local-6989586621681168209"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168209"><span class="hs-identifier hs-var">why</span></a></span></span><span>
</span><span id="line-2266"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><a href="GHC.Tc.Deriv.Utils.html#DerivEnv"><span class="hs-identifier hs-type">DerivEnv</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">denv_cls :: DerivEnv -&gt; Class
</span><a href="GHC.Tc.Deriv.Utils.html#denv_cls"><span class="hs-identifier hs-var">denv_cls</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168208"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168208"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-2267"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_inst_tys :: DerivEnv -&gt; [PredType]
</span><a href="GHC.Tc.Deriv.Utils.html#denv_inst_tys"><span class="hs-identifier hs-var">denv_inst_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168207"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168207"><span class="hs-identifier hs-var">cls_args</span></a></span></span><span>
</span><span id="line-2268"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">denv_strat :: DerivEnv -&gt; Maybe (DerivStrategy GhcTc)
</span><a href="GHC.Tc.Deriv.Utils.html#denv_strat"><span class="hs-identifier hs-var">denv_strat</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681168206"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168206"><span class="hs-identifier hs-var">mb_strat</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReaderT DerivEnv TcRn DerivEnv
forall (m :: * -&gt; *) r. Monad m =&gt; ReaderT r m r
</span><a href="../../transformers/src/Control.Monad.Trans.Reader.html#ask"><span class="hs-identifier hs-var">ask</span></a></span><span>
</span><span id="line-2269"></span><span>       </span><span class="annot"><span class="annottext">SDoc -&gt; DerivM SDoc
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; DerivM SDoc) -&gt; SDoc -&gt; DerivM SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
-&gt; Class
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; SDoc
-&gt; SDoc
-&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErr%27"><span class="hs-identifier hs-var">derivingThingErr'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; Bool
</span><a href="GHC.Tc.Deriv.Utils.html#isDerivSpecNewtype"><span class="hs-identifier hs-var">isDerivSpecNewtype</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168210"><span class="hs-identifier hs-var">mechanism</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168208"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168207"><span class="hs-identifier hs-var">cls_args</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168206"><span class="hs-identifier hs-var">mb_strat</span></a></span><span>
</span><span id="line-2270"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DerivStrategy GhcTc -&gt; SDoc
forall a. DerivStrategy a -&gt; SDoc
</span><a href="GHC.Hs.Decls.html#derivStrategyName"><span class="hs-identifier hs-var">derivStrategyName</span></a></span><span> </span><span class="annot"><span class="annottext">(DerivStrategy GhcTc -&gt; SDoc) -&gt; DerivStrategy GhcTc -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism -&gt; DerivStrategy GhcTc
</span><a href="GHC.Tc.Deriv.Utils.html#derivSpecMechanismToStrategy"><span class="hs-identifier hs-var">derivSpecMechanismToStrategy</span></a></span><span> </span><span class="annot"><span class="annottext">DerivSpecMechanism
</span><a href="#local-6989586621681168210"><span class="hs-identifier hs-var">mechanism</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168209"><span class="hs-identifier hs-var">why</span></a></span><span>
</span><span id="line-2271"></span><span>
</span><span id="line-2272"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivingThingErr%27"><span class="hs-identifier hs-type">derivingThingErr'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-2273"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#DerivStrategy"><span class="hs-identifier hs-type">DerivStrategy</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span>
</span><span id="line-2274"></span><span id="derivingThingErr%27"><span class="annot"><span class="annottext">derivingThingErr' :: Bool
-&gt; Class
-&gt; [PredType]
-&gt; Maybe (DerivStrategy GhcTc)
-&gt; SDoc
-&gt; SDoc
-&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingThingErr%27"><span class="hs-identifier hs-var hs-var">derivingThingErr'</span></a></span></span><span> </span><span id="local-6989586621681168204"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168204"><span class="hs-identifier hs-var">newtype_deriving</span></a></span></span><span> </span><span id="local-6989586621681168203"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168203"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621681168202"><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168202"><span class="hs-identifier hs-var">cls_args</span></a></span></span><span> </span><span id="local-6989586621681168201"><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168201"><span class="hs-identifier hs-var">mb_strat</span></a></span></span><span> </span><span id="local-6989586621681168200"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168200"><span class="hs-identifier hs-var">strat_msg</span></a></span></span><span> </span><span id="local-6989586621681168199"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168199"><span class="hs-identifier hs-var">why</span></a></span></span><span>
</span><span id="line-2275"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#sep"><span class="hs-identifier hs-var">sep</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Can't make a derived instance of&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-2276"></span><span>             </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">PredType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">PredType
</span><a href="#local-6989586621681168198"><span class="hs-identifier hs-var">pred</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168197"><span class="hs-identifier hs-var">via_mechanism</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2277"></span><span>          </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#nest"><span class="hs-identifier hs-var">nest</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168196"><span class="hs-identifier hs-var">extra</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#colon"><span class="hs-identifier hs-var">colon</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-2278"></span><span>         </span><span class="annot"><span class="annottext">Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#nest"><span class="hs-identifier hs-var">nest</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168199"><span class="hs-identifier hs-var">why</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-2279"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-2280"></span><span>    </span><span id="local-6989586621681168194"><span class="annot"><span class="annottext">strat_used :: Bool
</span><a href="#local-6989586621681168194"><span class="hs-identifier hs-var hs-var">strat_used</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc) -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (DerivStrategy GhcTc)
</span><a href="#local-6989586621681168201"><span class="hs-identifier hs-var">mb_strat</span></a></span><span>
</span><span id="line-2281"></span><span>    </span><span id="local-6989586621681168196"><span class="annot"><span class="annottext">extra :: SDoc
</span><a href="#local-6989586621681168196"><span class="hs-identifier hs-var hs-var">extra</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168194"><span class="hs-identifier hs-var">strat_used</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168204"><span class="hs-identifier hs-var">newtype_deriving</span></a></span><span>
</span><span id="line-2282"></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;(even with cunning GeneralizedNewtypeDeriving)&quot;</span></span><span>
</span><span id="line-2283"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span>
</span><span id="line-2284"></span><span>    </span><span id="local-6989586621681168198"><span class="annot"><span class="annottext">pred :: PredType
</span><a href="#local-6989586621681168198"><span class="hs-identifier hs-var hs-var">pred</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; [PredType] -&gt; PredType
</span><a href="GHC.Core.Predicate.html#mkClassPred"><span class="hs-identifier hs-var">mkClassPred</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621681168203"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[PredType]
</span><a href="#local-6989586621681168202"><span class="hs-identifier hs-var">cls_args</span></a></span><span>
</span><span id="line-2285"></span><span>    </span><span id="local-6989586621681168197"><span class="annot"><span class="annottext">via_mechanism :: SDoc
</span><a href="#local-6989586621681168197"><span class="hs-identifier hs-var hs-var">via_mechanism</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681168194"><span class="hs-identifier hs-var">strat_used</span></a></span><span>
</span><span id="line-2286"></span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;with the&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681168200"><span class="hs-identifier hs-var">strat_msg</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;strategy&quot;</span></span><span>
</span><span id="line-2287"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-2288"></span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#empty"><span class="hs-identifier hs-var">empty</span></a></span><span>
</span><span id="line-2289"></span><span>
</span><span id="line-2290"></span><span class="annot"><a href="GHC.Tc.Deriv.html#derivingHiddenErr"><span class="hs-identifier hs-type">derivingHiddenErr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-2291"></span><span id="derivingHiddenErr"><span class="annot"><span class="annottext">derivingHiddenErr :: TyCon -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#derivingHiddenErr"><span class="hs-identifier hs-var hs-var">derivingHiddenErr</span></a></span></span><span> </span><span id="local-6989586621681168192"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168192"><span class="hs-identifier hs-var">tc</span></a></span></span><span>
</span><span id="line-2292"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;The data constructors of&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681168192"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">PtrString -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ptext"><span class="hs-identifier hs-var">ptext</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; PtrString
</span><a href="GHC.Data.FastString.html#sLit"><span class="hs-identifier hs-var">sLit</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;are not all in scope&quot;</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-2293"></span><span>       </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;so you cannot derive an instance for it&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-2294"></span><span>
</span><span id="line-2295"></span><span class="annot"><a href="GHC.Tc.Deriv.html#standaloneCtxt"><span class="hs-identifier hs-type">standaloneCtxt</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Hs.Type.html#LHsSigWcType"><span class="hs-identifier hs-type">LHsSigWcType</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-2296"></span><span id="standaloneCtxt"><span class="annot"><span class="annottext">standaloneCtxt :: LHsSigWcType GhcRn -&gt; SDoc
</span><a href="GHC.Tc.Deriv.html#standaloneCtxt"><span class="hs-identifier hs-var hs-var">standaloneCtxt</span></a></span></span><span> </span><span id="local-6989586621681168191"><span class="annot"><span class="annottext">LHsSigWcType GhcRn
</span><a href="#local-6989586621681168191"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;In the stand-alone deriving instance for&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-2297"></span><span>                       </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">LHsSigWcType GhcRn -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">LHsSigWcType GhcRn
</span><a href="#local-6989586621681168191"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-2298"></span></pre></body></html>